Plugins you say?

0 views
Skip to first unread message

Andrés Villanueva

unread,
Jun 29, 2009, 10:37:50 AM6/29/09
to CslaGenerator
Hey everyone,

The following is intended to be an intoduction to plugins, hopefully it'll inspire someone to add some wiki content with samples and all!! ;)

-So what's a simple plugin?
-What can (or can't) I do with it?
-The source for cslagen looks big and scary. I'm scared!!
-But cslagen is written in C#, and I hate it!!
-OK, I'm hooked, how do I go about creating one?


So what's a simple plugin?

A simple plugin here is something that will let you interact with the metadata you create with cslagen and with the database schema you're currently connected to.


What can (or can't) I do with it?

You can't add a cool buttons to the ui, or make the different panels in the app look or behave any different. You can't change the way the code get's generated.

You can script common tasks such as
-Making the default friendly names even friendlier
-Or creating / modifying your default rules
-Or make massive upgrades to your object model (ever had to add a timestamp to 50+ objects?, rename columns?, add a CreatedBy, DateCreated and DateUpdated field to every object?)
-Creating all my editable roots and readonly collections for the whole DB in 2 clicks?

Well, YES!! You can even create a little ui for all of that (in a modal form) if you need to, or have your plugins output information to the output panel.



In short, you can mess with the metadata just as you would by hand using the UI (actually, you can break a few rules enforced by the UI even. I'm not suggesting that you do though...), but you can't change what get's generated based on that metadata.


The source for cslagen looks big and scary. I'm scared!!

Well, you don't need to know a whole lot in order to create a plugin. You don't even need the source to cslagen to create one or work with the. If anything, a little experience with plugins will make you at least a little less scared of the code base :)


But cslagen is written in C#, and I hate it!!

Well, you probably figured this one out by now: you don't have to do it in C# ;) (Curly braces' fans can of course do it too)


OK, I'm hooked, how do I go about creating one?

Well, that's what the linked project intends to show, but here's a brief text introduction.

1) Create a class library project.
2) Add a reference CslaGenerator.exe, DBSchemaInfo.dll and WeifenLuo.WinFormsUI.Docking.dll
3) Create a class that inherits CslaGenerator.Plugins.SimplePluginBase
4) Add a default constructor to it and add commands by calling the "AddCommand()" method. (More on that later)
5) Build.
6) Copy the dll to the app's "Plugins" folder.
7) Start CslaGenerator and behold the Plugins menu item with your commands!!



OK, so I've squeezed it in 7 lucky steps, but there's more to step #4 than meets the eye. That is where the magic happens, where the dull, time consuming, repetitive manual process becomes 2 clicks for the rest of the ride. That's where the sample project comes into play...

The code is short and simple. There are 2 "commands", one for adding rules to editable type objects and one for creating multiple root objects and readonly collections (this last one with a little UI). The command that adds rules is not intended to work for everyone as is, it's just there as an example of what you can do.

Well, I hope you enjoyed this introduction, you can now go download the code for this here.

Of course, remember to backup your projects before messing with plugins!!!!

Have fun!

--
Andrés

pandelis

unread,
Jul 1, 2009, 1:36:52 AM7/1/09
to CslaGenerator
I just tested those plugins and they are amazing! Especially the
default rules plugin was one of the few things that was missing!

I only have one question. You say that we cant change the way the code
is being generated. I have created a custom authentication system and
i need to add 4 lines of code to each of my objects for each
permission needed. Can i use a plugin to make it happen automatically
or is this a template issue?

Andrés Villanueva

unread,
Jul 1, 2009, 10:13:55 AM7/1/09
to CslaGe...@googlegroups.com
Glad you liked it!!
Unfortunately, the templates just translate metadata to code. They don't know about custom code sections.
You're better off making those changes in the templates themselves.
--
Andrés

Kevin Welsh

unread,
Jul 1, 2009, 12:29:35 PM7/1/09
to CslaGe...@googlegroups.com

What would it take to tweak the current templates to allow them to trigger a “user defined template”?

 

That way no-one has to worry about attempting to keep their customized templates in sync with future updates.

 

Is this something that can be done?

 

Kevin

Fahmi

unread,
Jul 9, 2009, 9:43:40 PM7/9/09
to CslaGenerator
Hi,
I'm have you found any way to do this?
I'd like to create plug ins that can add some custom properties and
additional custom template

Regards
Fahmi

On Jul 1, 11:29 pm, Kevin Welsh <kwe...@welshtechnologies.com> wrote:
> What would it take to tweak the current templates to allow them to trigger a "user defined template"?
>
> That way no-one has to worry about attempting to keep their customized templates in sync with future updates.
>
> Is this something that can be done?
>
> Kevin
>
> From: CslaGe...@googlegroups.com [mailto:CslaGe...@googlegroups.com] On Behalf Of Andrés Villanueva
> Sent: Wednesday, July 01, 2009 10:14 AM
> To: CslaGe...@googlegroups.com
> Subject: Re: Plugins you say?
>
> Glad you liked it!!
> Unfortunately, the templates just translate metadata to code. They don't know about custom code sections.
> You're better off making those changes in the templates themselves.
>

Andrés Villanueva

unread,
Jul 10, 2009, 1:10:40 PM7/10/09
to CslaGe...@googlegroups.com
I think Kevin's suggestion is doable. I'll definitely look into it for next release.
--
Andrés
Reply all
Reply to author
Forward
0 new messages