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