Visual Studio Development Bookmark and Share   
 index > Visual Studio Guidance Automation Toolkit > Modification of a SplitAndAddItemsFromString action
 

Modification of a SplitAndAddItemsFromString action

Hi,
I would like to change splitRegex in this action to split passed string into 3 groups (filename and content, and a folder name to which class will be added), instead of current two (filename and content). Currently all templates generates one string for all business entities and we have string like:

//begin "Client.cs"
here is the content
//end "Client.cs"

To do that I have modified all templates to add folder name and I have added something like this:

// begin "Client.cs"
// folderName "Client"
here is the content
//end "Client.cs"

So in this case I have to change splitRegex to get value which is after this text '// folderName ' and in within "" to be my folder name.


Code Snippet

// begin "filename"
here is the content
// end "filename"



For more information here is the regex I would like to change:

Code Snippet

static readonly Regex splitRegex = new Regex(@"^// name ""(?<name>[^""]+)""\n^// begin ""(?<filename>[^""]+)"".?$\n(?<content>.*)^// end ""\k<filename>"".?$", RegexOptions.Multiline | RegexOptions.Singleline);


and here is code of a "Execute" method which splits generated string into separate files and where I would like to get folder name:

Code Snippet

const string FilenameGroups = "filename";
const string ContentGroups = "content";
const string FolderNameGroups = "folderName";

public override void Execute()
{
DTE vs = GetService<DTE>(true);
projectItems = new List<EnvDTE.ProjectItem>();
for(Match match = splitRegex.Match(content); match.Success; match = match.NextMatch())
{
string relativeFileName = match.Groups[FilenameGroups].Value;
string fileName = Path.GetFileName(relativeFileName);
string relativeTargetPath = Path.GetDirectoryName(relativeFileName);

... here I would like to get folder name like:
string relativeFileName = match.Groups[FolderNameGroups ].Value

}

}

TIA,
Kind Regards,
Lukasz

faf38  Tuesday, May 15, 2007 10:44 AM

Hi Lukasz,

Which is the problem you're having while trying modify the regex? Any particular errors?

thanks,

-Victor.

vga  Saturday, June 02, 2007 4:08 PM

Hi Lukasz,

Which is the problem you're having while trying modify the regex? Any particular errors?

thanks,

-Victor.

vga  Saturday, June 02, 2007 4:08 PM
Hi Victor,
Thanks for your post Smile. I have solved this problem with help OmegaCoder. When I take a look I have good regex, but I do not correctly implement Execute method. The regex which do the trick is:

Code Snippet

static readonly Regex splitRegex
= new Regex(@"^// begin ""(?<filename>[^""]+)"".?$\n^// name ""(?<name>[^""]+)"".?$\n(?<content>.*)^// end ""\k<filename>"".?$", RegexOptions.Multiline | RegexOptions.Singleline);


and the folder name is added after file name as:

// name "here is a filename"

Regards,
Lukasz


faf38  Saturday, June 02, 2007 5:59 PM

You can use google to search for other answers

Custom Search

More Threads

• Failed install for Feb Release of GAT
• FileCodeModel null on none project file...
• Dec '06 WSSF fails to install after installing Feb 07 GAX and GAT
• Linking DSL Files
• "Add new module" recipe customization
• Custom Argument Type and History of T4
• Application Block Software Factory templates don't appear in VS 2008
• Problem with business module creation (Smart Client Software Factory)
• t4 template code appending
• Fail to register Guidance Package from Solution Manager