Options :
- do nothing, let the program crash
- replace invalid chars with valid ones, underscore or so
- throw an exception, so the user must change the invalid name
- inform the user that the name might cause problems
Option 1 : a no-go, problems must be fixed.
Option 2 : introduces other problems, because for one you have the possibility of 'renaming' a project into another existing one, and the user does not know.
Option 3 : that is a possible approach, but who decides what is a bad character? in 1990 a space was invalid for a file name (yep, I'm THAT old) and now it is not anymore
Option 4 : I think this is the best, you inform the user that a certain setting could pose a problem, but let the program continue. If it is a problem the user knows what to do to make it work, or should now ;-)
Now from version 1.5 onwards, CCNet has a neat validation system. It allows to set certain conditions as an error (throw exception type), or set as warning (just inform the user). And it shows in the log AND in the CCNetValidator program. How to use this neat system ? read on ...
I'll take the publisher from my previous posts as an example, and update it with the validation. Now this is a very basic publisher, but is perfect as a basic example.
The only thing needed to do is implement IConfigurationValidation which can be found in the config namespace : ThoughtWorks.CruiseControl.Core.Config.IConfigurationValidation
This will add a procedure :
public void Validate(IConfiguration configuration, object parent, Core.Config.IConfigurationErrorProcesser errorProcesser) |
For showing a warning use : errorProcesser.ProcessWarning("This is a warning");
For showing an error, and prevent starting ccnet : errorProcesser.ProcessError("This is an error");
Very easy ! A bit more meaningful :
public void Validate(IConfiguration configuration, object parent, Core.Config.IConfigurationErrorProcesser errorProcesser) |
An even better idea for a validation is the following :
public virtual void Validate(IConfiguration configuration, object parent, IConfigurationErrorProcesser errorProcesser) |
No comments:
Post a Comment