Some days ago I published the 1-Click Maintenance plug-in here. I promised that I will also provide the source code. Here we go: Download source code (171.2K)
If you are not a programmer you can stop reading. For all the others, you're welcome to take a look at the C# project and maybe even extend it...? Extending the plug-in is not that hard. And I know you already have some new database checks in your mind which you want to see in action.
So here is what you have to do in order to implement and run your own checks. Open the project in Visual Studio 2008 and locate the class SampleCheck:
class SampleCheck : DatabaseCheck, IFixable
The sample check gives you an idea what is necessary for a new database check. Just copy and paste this class or extend it. First you have to define the title and the description of the new database check. Then you have to implement the Analyze method, that's where the real logic is located:
public override void Analyze(IStatusDisplay statusDisplay)
Within the Analyze you probably find some issues, just add them to the Results list. If you need to show a message to the user don't show a message box, instead use the Messages property. One reason for that is that we don't want to interrupt the process and it also has to run in batch mode.
If your check can also fix the found issues you can implement the IFixable interface for your class. This should add a new method called Fix:
public void Fix(IStatusDisplay statusDisplay)
Within the Fix method make sure you iterate through the Results and fix one after the other. Keep in mind that the user might disable some results, so check the Active property of the result (result.Active). Also in this method you can log messages and errors in the Messages property.
After you have finished implementing your database check class you have to add it to the Controller. Locate the Controller.InitializeChecks() method and add a new instance of your class there.
That's it. If you need more detailed information take a look at the other database checks.
In order to compile and run the plug-in you have to set the correct reference path for the Topobase related assemblies (go to Project - Properties - Reference Paths) and the correct build path (Project - Properties - Build - Ouput path).
Finally select the Topobase 2010 Administrator executable to start and debug the plug-in (Project - Properties - Debug - Start external program).
You are welcome to send me any feedback (or new database checks :-)
Thanks!
AUTODESK DOES NOT GUARANTEE THAT YOU WILL BE ABLE TO SUCCESSFULLY DOWNLOAD OR IMPLEMENT ANY SAMPLE CODE. SAMPLE CODE IS SUBJECT TO CHANGE WITHOUT NOTICE TO YOU. AUTODESK PROVIDES SAMPLE CODE "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL AUTODESK OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF DATA, OR LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, THAT MAY OCCUR AS A RESULT OF IMPLEMENTING OR USING ANY SAMPLE CODE, EVEN IF AUTODESK OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
Comments