Archived Thread: 'ODS Aware Batch Controller (BLL) Generator'
-
ODS Aware Batch Controller (BLL) GeneratorPosted by datacop on Saturday, November 04, 2006
I've modified the code generator to provide the capability to batch create ODS aware Controller stubs based on the tables..
http://www.codeplex.com/WorkItem/View.aspx?ProjectName=actionpack&WorkItemId=5155 -
Re: ODS Aware Batch Controller (BLL) GeneratorPosted by sherpa99 on Monday, November 06, 2006
datacop -
Kudos. This is a great concept -- I've started to play with it, but I'm having some trouble ... here is where I've placed your files.
WekeRoad.ActionPack\SampleWeb\Dev\BatchControllerGenerator.aspx
WekeRoad.ActionPack\SampleWeb\Dev\CodeTemplates\ODSController.txt
WekeRoad.ActionPack\SubSonic\Builder\CodeGeneration.csI can build a clean compile --but when I run the BatchControllerGenerator.aspx page, it errors with a message
"Error: Object reference not set to an instance of an object."In the debugger, I've found that it's having trouble finding the template file.
Specifically, line GetODSClass method -- Line 719 of CodeGeneration.cs returns null, see below.
string odsControllerTemplate = ResourceHelper.GetString("ODSController");
So, the ResourceHelper.GetString it the root of the problem, it gets nothing back from the SubSonicConfig.TemplateDirectory property;
I believe I need to modify the webconfig to set this TemplateDirectory, correct? But how?
-
How to create .txt templates from the resource file.Posted by datacop on Monday, November 06, 2006
In order to use text file templates, you need to strip out all the templates from the resource file. For example, create a folder say "C:\Subsonic\Templates", then open up the resource file and create a blank text file for each resource listed, with the same name as the resource name. For example, the Scaffold resource template fiel would be "Scaffold.txt".
Then, you need to open each of the text files and copy and paste that resources template data into the text file, matching resource name with text file name.
Finally, in the SubSonicService section of your web.config, set the TemplateDirectory option to the full physical path of the template directiory you created in the first step.
-or-
You can create a new resource in the resource file named ODSController, and copy the contents of the ODSController file into the new resources data section, compile and run.
Scripting the resources out as .txt files is a pain in the rear to do the first time around, but it does make it nice to have individual template files when creating new template based functionality. Idealy, all the individual .txt files will be merged back into the resource file for the production releases.
-
Re: How to create .txt templates from the resource file.Posted by Elmar on Tuesday, November 14, 2006
First of all, thank you for providing this feature for the community!
I am experiencing the same error. Unfortunatly a can“t follow your explanation on how to solve this. Is there any documentation/example on how to get this done?
Elmar
-
Re: How to create .txt templates from the resource file.Posted by Elmar on Wednesday, November 15, 2006
Even if I create a ResourceFile ODSController.resx in App_GlobalRessources it will still throw the above mentioned exception.
I left the default name for the first value in place and copied all contents from the ODSController.txt into the value section.
-
Re: How to create .txt templates from the resource file.Posted by datacop on Wednesday, November 15, 2006
If you download the source tree from codeplex, the templates are all in a directory..
You have to set the location of your template directory in your web.config in the subsonicservice section.
-
BLL Generator InstallPosted by Elmar on Thursday, November 16, 2006
Thanks Datacop! To make people use this tool it is essential to provide some more basic information to get them into business quick. Maybe I can help out.
For new Users ->
Assuming that you stick with the overall Directory structure provided in the SubSonic sample apps this is what you have to do:
- I figuered out that it is best to append the SubSonic Source project into your existing Solution (add existing project) so that you can alter things as needed.
- to make the BLL Generator work for you, just download the Generator files from http://www.codeplex.com/WorkItem/View.aspx?ProjectName=actionpack&WorkItemId=5155
- Unpack the archive and replace CodeGeneration.cs located in <SubSonicSourceProject>\Builder\ with the file provided in the archive.
- Locate the "SubSonicService" line in your (Web)-projects Web.config. Add the templateDirectory attribute
<SubSonicService defaultProvider="SqlDataProvider" spClassName="SPs" fixPluralClassNames="true" templateDirectory="FullPathToTheCodeTemplatesDirectory">
The full path should point to <PathToYourWebProject>\Dev (or _Dev)\CodeTemplates because this where all SubSonic Code generation templates are stored. As we want additional code to be generated (our BLL) that is also the place to put the ODSController.txt file from the downloaded archive.
Last thing is to add the actual web page that lets you configure which files should be generated by the BLL Generator. It is recommended to put this file - BatchControllerGenerator.aspx- into the same location where the other code generating aspx files reside. Again, if you are using the default directory structure that would be <yourWebProject>\Dev (or _Dev).
I hope you could follow along and now have a working BLL stub.
Elmar
-
Re: BLL Generator InstallPosted by datacop on Friday, November 17, 2006
Thanks Elmar..
Keep in mine, my ODS Controller generator is not part of the official source build.. and I'm not sure if it will be or not.. so of course, use at your own risk.
-
Re: BLL Generator InstallPosted by DanKline on Friday, December 15, 2006
Hi DataCop,
>>>Do you have a version of the batchController that works with the latest release(13989)? I tried to merge the ODSregions into the generator and >>>the build went fine (after a few tweeks), but the generator creates a blank controller file before it generates an instance error.
Never mind the code. I got it to work by adding the ODSController to the resource file. That was easier.
I think the Batch Controller Generator is important to accelerating adoption of the SUbSonic DAL. I'd like to lobby for it's incorporation into the builds.
Dan
-
Re: BLL Generator InstallPosted by datacop on Friday, December 15, 2006
Since the controller and template haven't made it into the source trunk, I've not made an effort to update or enhance it..
It's kind of difficult to do since there are so many changes being made right now to keep everything in synch with working outside the tree...
-
Re: How to create .txt templates from the resource file.Posted by DevInstinct on Friday, December 15, 2006
Suggestion:
SubSonic could use embeded resource files (that is, in file properties -> Build -> Embeded Resource) instead than a standard resource file with strings. Easy to access at runtime (see GetManifestResourceStream method) and easier to manage in the project solution.
Martin
-
Re: BLL Generator InstallPosted by DanKline on Saturday, December 16, 2006
Hi DataCop,
I've been playing with the generator. I had one "gotcha" in that I forgot to change the connection string in the web.config. I'm running my Northwinds on SQL2005. But even after I corrected the connection string, I'm still only pulling 11 of the 13 datafiles for generation as evidenced on the batch controller screen and output. I'll poke around a bit and see what I can find. Let me know if you have an idea about what is happening.
...
I looked into it. The logic in the handling of the tables list in the BatchControllerGenerator.aspx was probably outdated. Becasue the SQL query from GetTables works with the DBO Schema, the code that was there was creating a problem and wasn't serving a meaningful purpose. The code at the top of the BatchScaffoldGenerator was working perfectly, so I stole the code an logic from there. Now it works perfectly on my files, though it still seems to have a problem with Northwinds ... especially with spaces in Filenames. I never got past the "StartIndex must be greaterr than 0" error, but it seems to have been something peculiar in the Northwinds Database ... perhaps becasue it doesn't have ithe "ISxxx" and CreatedBy and ModifiedBy fields.
It is a VERY useful piece of code. Thank you.
Dan.
-
Re: ODS Aware Batch Controller (BLL) GeneratorPosted by DanKline on Saturday, December 30, 2006
I've integrated the ODS Batch Controller into SubSonic 106 but in the process I stumbled on a chunk of code in GetODSClass that needs a tweek.
The issue arises with the "CustomerCustomerDemo file which is composed of 2 fields that are both primary keys. The logic to clean up the paramList assumes that there was at least one non-primarykey value in the schema. Thus, with the CustomerCustomerDemo file, we are trying to remove two characters from an empty string which generates a startIndex error. I've added the highlighted lines to test for the condition and skip the paramList cleanup if the empty string condition exists.
// Establish our table schema
TableSchema.Table tbl = DataService.GetTableSchema(table);
// Loop through all the columns and setup are replacement fields
foreach (TableSchema.TableColumn col in tbl.Columns)
{
if (col.IsPrimaryKey)
{
keyfieldDataType = Utility.GetCSharpVariableType(col.DataType);
keyfieldName = Utility.KeyWordCheck(col.ColumnName);
}
else
{
if (!Utility.IsAuditField(col.ColumnName) && !Utility.IsLogicalDeleteField(col.ColumnName))
{
paramList += Utility.GetCSharpVariableType(col.DataType) + " " + Utility.KeyWordCheck(col.ColumnName) + ", ";
objectFieldHandler += " tblObject." + Utility.KeyWordCheck(col.ColumnName) + " = " +
Utility.KeyWordCheck(col.ColumnName) + ";" + Environment.NewLine;
}
}
}
//Test for all columns being primary keys thus paramList is empty
if (paramList != string.Empty)
{
// Now that the colums are parsed.. clean up the paramlist
paramList = paramList.Remove(paramList.Length - 2);
}Also, the GenerateODSController() class must be declared as public to be reachable by the batchControllerGenerator.aspx page.
If there is an interest, I can upload a copy of the codeGeneration.cs, batchControllerGenerator.aspx, and the resources.resx so that it is easier for folks to integrate the ODSController into the current release.
-
Re: ODS Aware Batch Controller (BLL) GeneratorPosted by Meastro on Sunday, March 11, 2007
Hi,
I'm interested in the ods controller batch generator for the current release. I hope you can send me a copy or upload it here: http://www.codeplex.com/actionpack/WorkItem/View.aspx?WorkItemId=5155