Filename with cs in it

Posts   
 
    
tommy
User
Posts: 5
Joined: 28-Feb-2007
# Posted on: 28-Feb-2007 09:14:04   

Hello LLBLGen Team,

I have modify the Codegenerator from SDK. Now it can add nested partial classes in VS.NET 2005 Projectexplorer like WindowsForms .designer.cs named e.g. CustomerCollection.Code.cs. In VS.NET 2005. I only change some code in the Method ConstructProjectFileContents, file ProjectFileCreator.cs

for (int i = 0; i < fileNames.Count; i++) { string filename = (string)fileNames[i];

string buildAction = "Compile";
// chop off destination folder.
filename = filename.Replace(fullPath.TrimEnd('\\') + @"\", "");

// check if the extension of the file is the same as the extension
if (filename.Substring(filename.Length - 3, 3) != ("." + executingGenerator.LanguageToUse.FileExtension))
{
    // not a code file.
    buildAction = "None";
}

**string filenamePartial = filename.Replace(".cs", "") + ".Code.cs";**

**string filename2 = filename.Substring(filename.LastIndexOf('\\') + 1,
    filename.Length - filename.LastIndexOf('\\') - 1);**

if (versionToTarget == TargetVersion.VsNet2005)
{
    fileIncludes.AppendFormat("\t\t<{0} Include=\"{1}\"><SubType>Code</SubType></{0}>{2}", buildAction, filename, Environment.NewLine);

    **fileIncludes.AppendFormat("\t\t<{0} Include=\"{1}\">{2}", buildAction, filenamePartial, Environment.NewLine);
    fileIncludes.AppendFormat("\t\t<DependentUpon>{0}</DependentUpon>{1}", filename2, Environment.NewLine);
    fileIncludes.AppendFormat("\t\t</{0}>{1}", buildAction, Environment.NewLine);**
}
else
{
    fileIncludes.AppendFormat("\t\t<File RelPath = \"{0}\" BuildAction = \"{1}\"/>{2}", filename, buildAction, Environment.NewLine);
}

}

Now I have problems with Filename with cs in it. Follow problem:

E.g. the filename is CustomerDemographicsCollection.cs. The Codegenerator create a file named CustomerDemographiCollection.Class.cs, without cs by ...Demographi.... I don't know why this happens. I changed more code in the Codegenerator in the file CodeEmitter.cs, the method CreateFilename an change the two replaces - extension and elementName.

//orginal //return filenameFormat.Replace("[elementName]", elementName).Replace("[extension]", extension);

//changed return filenameFormat.Replace("[extension]", extension).Replace("[elementName]", elementName);

Do you have a idea what i made wrong in the Codegenerator file ProjectFileCreator.cs?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39786
Joined: 17-Aug-2003
# Posted on: 28-Feb-2007 10:40:03   

I'm not entirely following you, so if you could attach the new projectfile task performer code it would be great.

You should look into the Path class, which offers you features to strip off an extension and combine path elements to new paths/filenames.

To debug this code, you should follow these steps: place the task performer dll + pdb file (debug build simple_smile ) into the taskperformers folder and run llblgen pro. Then in vs.net you load the task performer sourcecode and press cntrl+alt+p. this will open the attach to process dialog. Attach to llblgenpro.exe. Set a breakpoint and then generate code.

Frans Bouma | Lead developer LLBLGen Pro
tommy
User
Posts: 5
Joined: 28-Feb-2007
# Posted on: 28-Feb-2007 13:54:47   

Thank you for debugging tip - it's great!

More information:

For using own code into the generated code i wrote new templates for new sourcefiles. E.g. entityCollection.Code.template

using System;
using System.Data;
using System.Collections.Generic;
using System.ComponentModel;
using System.Xml;

#if !CF
using System.Runtime.Serialization;
#endif

using <[RootNamespace]>.EntityClasses;
using <[RootNamespace]>.FactoryClasses;
using <[RootNamespace]>.DaoClasses;
using <[RootNamespace]>.HelperClasses;

using SD.LLBLGen.Pro.ORMSupportClasses;

namespace <[RootNamespace]>.CollectionClasses
{
#if CF
    [SD.LLBLGen.Pro.ORMSupportClasses.Serializable]
#else
    [Serializable]
#endif

    public partial class <[CurrentEntityName]>Collection : EntityCollectionBase<<[CurrentEntityName]>Entity>
    {

    }
}

Add new binding. E.g. SD.TemplateBindings.SharedTemplates.NET20.templatebindings

<templateBinding templateID="Custom_EntityCollectionPartialClassTemplate" filename="SharedTemplates\Net2.x\C#\entityCollection.Code.template"/>

And a new task for it. E.g. SD.Tasks.SelfServicing.tasks

  <!--Custom Partial Collection Classes-->
  <task name="SD.Tasks.SelfServicing.CollectionPartialClassesFileCreator" assemblyFilename="SD.LLBLGen.Pro.TaskPerformers.dll"
       taskPerformerClass="SD.LLBLGen.Pro.TaskPerformers.CodeEmitter" description="Generates the partial collections for selfservicing scenarios" isOptional="false">
    <supportedPlatforms/>
    <supportedTemplateGroups>
      <templateGroup name="SelfServicing"/>
    </supportedTemplateGroups>
    <dependencies>
      <dependency name="SD.Tasks.SelfServicing.CollectionClassesDirectoryCreator"/>
    </dependencies>
    <parameters>
      <parameter name="destinationFolder" defaultValue="CollectionClasses" isOptional="false" description="The folder to generate the code in"/>
      <parameter name="filenameFormat" defaultValue="[elementName]Collection.Code.[extension]" isOptional="false" description="The destination file format specification"/>
      <parameter name="templateID" defaultValue="Custom_EntityCollectionPartialClassTemplate" isOptional="false" description="The ID of the template to use." valueType="templateID"/>
      <parameter name="emitType" defaultValue="allEntities" isOptional="false" description="The type of code generation to perform." valueType="emitType"/>
      <parameter name="templateBindingDefinitionName" defaultValue="" isOptional="true" description="The name of the TemplateBindings from which to pick the templateID specified. Specifying this parameter will always force the templateID to be picked from the templateBindings with the name specified."/>
      <parameter name="failWhenExistent" defaultValue="true" isOptional="true" description="Flag to signal what to do when the destination file already exists." valueType="boolean"/>
    </parameters>
  </task>
  <!--CollectionClasses-->

now i see in the solution explorer of VS.NET 2005 followed structure.

... CustomersCollection.cs |_CustomersCollection.Code.cs OrdersCollection.cs |_OrdersCollection.Code.cs OrderDetailsCollection.cs |_OrderDetailsCollection.Code.cs ...

for this structure you have to extend the Project-File with the <DependentUpon></DependentUpon> tag

the "new" sourcecode is attached

Thx

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39786
Joined: 17-Aug-2003
# Posted on: 01-Mar-2007 10:32:54   

Thanks for sharing! simple_smile Shall I move the thread to the templates forum?

Btw you don't have to inherit from entitycollectionbase again in your partial class, that's already done in the generated class.

Frans Bouma | Lead developer LLBLGen Pro