Displaying error returned by server side business rules validation.

Displaying error returned by server side business rules validation.

Old forum URL: forums.lhotka.net/forums/t/921.aspx


oshokodk posted on Wednesday, August 16, 2006

I am trying to

I am not using data portal feature of CSLA. Save process consists of write object into XML document, call web service method (not colas based), merge server response into object. Web service method can fail to save objects for variety of reasons (server side business rules validation, data integrity errors, etc.). If it fails, it return description of the problem. I want to integrate this status into string returned by BusinessBase.IDataErrorInfo.Error.

I see several methods, but I don't like any of them.

1. keep error description in data member of my class, override by BusinessBase.IDataErrorInfo.Error to return this error or redirect call to base class.

2. Add this error to broken rules list.

- BrokenRule class doesn't have public setters nor public constructor. Hack it and implement way of constructing broken rule without RuleMethod.

- Fake RuleMethod argument of BrokenRule constructor by creating this object on stack and then calling BrokenRule constructor.

- Be good citizen and implement proper business rule that check local data member of my class and fails if this member is not empty. I don't like since this rule will be checked all the time and will slow loading time of large collections.

Any suggestions?

Any changes in 2.1 that will help this situation?

vargasbo replied on Thursday, August 17, 2006

It's really hard to say much to your question, since the data portal is the biggest part of the Csla. At this point I'm assuming your just using the Csla as a guide framework.

Hard to help out with out seeing some code.

Brian Criswell replied on Thursday, August 17, 2006

How many items are you referring to when you say a large collection, and what are your time constraints.

oshokodk replied on Thursday, August 17, 2006

Collections can be larger than 20k. I am looking forward to 2.1 per-class validation rules. In mean time I implemented custom rule that passes special property of the object as error description. This was the only way I could work around private and internal methods and classes of valiadtion rules area.

The only inconvinence that I need to add this rule and this rule stays in collection of business rules for lifetime of the object.

RULE:

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods")]

public static bool ServerSideValidation(object target, RuleArgs e)

{

      string value = (string)Utilities.CallByName(target, e.PropertyName, CallType.Get);

      if (!string.IsNullOrEmpty(value))

      {

         e.Description = value;

         return false;

      }

      else

         return true;

}

USAGE:

[Browsable(false)]

const string ServerSideValidationStatusName = "ServerSideValidationStatus";

public string ServerSideValidationStatus

{

get { return _ServerSideValidationStatus; }

set

{

_ServerSideValidationStatus = value;

if (string.IsNullOrEmpty(_ServerSideValidationStatus))

{//remove broken rule

ValidationRules.CheckRules(ServerSideValidationStatusName);

}

else

{//add broken rule

ValidationRules.AddRule(CorpTax.ETS.Common.BusinessEntities.Validation.CommonRules.ServerSideValidation, ServerSideValidationStatusName);

ValidationRules.CheckRules(ServerSideValidationStatusName);

}

}

}

Copyright (c) Marimer LLC