Translations for exceptions in WPF binding

Posts   
 
    
Posts: 34
Joined: 05-Mar-2008
# Posted on: 27-Jan-2011 12:54:25   

Hi,

I use WPF databinding to entities. Really important feature of my application is localization (GUI and all messages etc.). Language and culture can be changed in runtime. I use custom validation described here: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=15343

If I bind decimal value to entity field which is decimal(18,6) in my database (SQL server 2008 ) and write more than 18 digits I receive the following exception.

The precision of value '123456789012345676.1' is larger than the precision of the field: '18' and will cause an overflow in the database. Parameter name: DivisibleBy

at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.ValidateValue(IEntityField2 fieldToValidate, Object& value, Int32 fieldIndex) at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.SetValue(Int32 fieldIndex, Object value, Boolean performDesyncForFKFields) at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.SetValue(Int32 fieldIndex, Object value) at MyProject.DataAccess.Core.EntityClasses.CommonEntityBase.SetValue(Int32 fieldIndex, Object value) in D:\Programming\MyProject_Trunk\src\DataAccess\MyProject.DataAccess.Core\MyProjectSpecific\CommonEntityBase.cs:line 690 at MyProject.DataAccess.Core.EntityClasses.InputFormatDecimalEntity.set_DivisibleBy(Nullable`1 value) in D:\Programming\ MyProject _Trunk\src\DataAccess\MyProject.DataAccess.Core\DatabaseGeneric\EntityClasses\InputFormatDecimalEntity.cs:line 696

The behaviour is correct and error message is correctly set to this message. But how to translate this message? Is it possible to provide custom messages for all exceptions thrown by ORM and change them during runtime? Can you provide the list of possible exceptions during setting entity property?

Application specification: SQLServer 2008 WPF 4.0, DevExpress Controls 10.2.4 ORM version 2.6.10.0225

Regards, David

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 27-Jan-2011 16:33:16   

End users should NEVER be seeing internally generated exceptions, so they should not really need to be translated. You should as a bare minimum have a top level exception handler at the start point of the application to catch anything unhandled elsewhere, and provide a generic "An unexpected error occurred - please contact support" type error message (obviously this message should be localized simple_smile )

Matt

Posts: 34
Joined: 05-Mar-2008
# Posted on: 28-Jan-2011 08:06:34   

Hi,

I totally agree with you in general but I think you have misunderstood me in this particular problem. As I said I use WPF databinding to entities. If user types digits into DevExpress TextEdit (its control like a WPF TextBox) this string is converted to decimal and automatically set to property. Control is validated on property changed event and responds to IDataErrorInfo and exceptions. And here is my problem - if user sets value which has more than 18 digits exception is thrown inside entity set method. Exception thrown is then AUTOMATICALLY handled by WPF binding engine and this exception error message is set to error info in the control (you may see this in the link below).

My question is how to handle this exception (I cannot catch it globally)? Is it possible to change message for this exception so it would be translatable? Or can you suggest any other solution?

Image: http://img442.imageshack.us/img442/6758/messageq.jpg

Regards, David

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 28-Jan-2011 19:37:02   

Some options:

a. Go to CommonEntityBase class (at your EntityClasses folder). Then in the custom code region do this:

// __LLBLGENPRO_USER_CODE_REGION_START CustomEntityCode
public override void SetEntityFieldError(string fieldName, string errorMessage, bool append)
{
    // customize the messages
    if (errorMessage.StartsWith("The scale of value"))
    {
        errorMessage = "Your input number is wrong dude.";
    }

    // set the error
    base.SetEntityFieldError(fieldName, errorMessage, append);
}
// __LLBLGENPRO_USER_CODE_REGION_END

b. Turn off the built-in validation and do it yourself. You can do this in your entity validators, or in a common validator.

c. Trap the exception in your GUI. I don't know how that control works, but maybe you can subscribe to an event and modify the message. See the documentation of the control to see the available events.

David Elizondo | LLBLGen Support Team