Business Operation Class

Each class representing a Business Operation should implement the IBusinessOperation interface. However, it is good practice to use the readily available BusinessOperationBase basic class and implement a descendant of this class.

The BusinessOperationBase class provides all basic BO functionality:

  • events generation,
  • events processing,
  • implementation of properties and methods declared by the IBusinessOperation interface.

In addition, the BusinessOperationBase class exposes numerous static methods for accessing the BO metadata. It also exposes factory methods for creating BO instances. For more information, see the BusinessOperationBase topic.

When developing a BO class that derives from BusinessOperationBase, it is usually sufficient to declare the parameters of the BO (input parameters, output parameters) and specify the context (if needed). The BusinessOperationBase class will do the rest.

Let's consider an example of a context-dependent BO. The context is a list of Orders objects. The base class is BusinessOperationBase. The BO solves the task of changing the freight cost according to the percent value specified in the "Order" document.

  • c#
  • VB

/// <summary>
/// Context BO. Context is a list of "Order" objects.
/// It changes the freight cost in the selected Orders
/// </summary>
[DisplayName("Changing the freight cost")]
[Description("Changes the freight cost based on the specified percent value")]
[ImageName("BO_Sale")]
[ExecutionWay(ExecutionWays.Synchronous)]
[ContextViewType(ContextViewType.Any)]
[BusinessOperationCategory("Orders"), BusinessOperationCategory]
[DefaultOperationService(typeof(ChangeFreightContextDefaultImpl))]
public class ChangeFreightContext : BusinessOperationBase
{
  private List<string> _processedOrdersLog;
  /// <summary>
  /// The context property is decorated with a special attribute. The framework analyzes the type of this property and 'decides', which context the
  /// business operation is intended for, and then initializes the property prior to executing the BO
  /// </summary>
  [ContextProperty(ObjectsCriteria = "[Number] != '010248'", ObjectsCriteriaMode = TargetObjectsCriteriaMode.TrueForAll)]
  public ICollection<Order> Orders { get; set; }
  /// <summary>
  /// The input parameter of the BO. The framework recognizes the input parameters by the presence of a public setter.
  /// The view for entering the input parameter values by the user is generated based on the input parameters
  /// at the moment of starting the BO.
  /// </summary>
  [DisplayName("Value, %")]
  public double Percent { get; set; }
  /// <summary>
  /// The output parameter. It contains text messages on the processed orders.
  /// </summary>
  public List<string> ProcessedOrdersLog
  {
    get
    {
      return _processedOrdersLog ?? (_processedOrdersLog = new List<string>());
    }
  }
}

''' <summary>
''' Context BO. Context is a list of "Order" objects.
''' It changes the freight cost in the selected Orders
''' </summary>
<DisplayName("Changing the freight cost")> _
<Description("Changes the freight cost based on the specified percent value")> _
<ImageName("BO_Sale")> _
<ExecutionWay(ExecutionWays.Synchronous)> _
<ContextViewType(ContextViewType.Any)> _
<BusinessOperationCategory("Orders"), BusinessOperationCategory> _
<DefaultOperationService(GetType(ChangeFreightContextDefaultImpl))> _
Public Class ChangeFreightContext
  Inherits BusinessOperationBase
  Private __processedOrdersLog As List(Of String)
  ''' <summary>
  ''' The context property is decorated with a special attribute. The framework analyzes the type of this property and 'decides', which context the
  ''' business operation is intended for, and then initializes the property prior to executing the BO
  ''' </summary>
  <ContextProperty(ObjectsCriteria := "[Number] != '010248'", ObjectsCriteriaMode := TargetObjectsCriteriaMode.TrueForAll)> _
Public Property Orders As ICollection(Of Order)
  ''' <summary>
  ''' The input parameter of the BO. The framework recognizes the input parameters by the presence of a public setter.
  ''' The view for entering the input parameter values by the user is generated based on the input parameters
  ''' at the moment of starting the BO.
  ''' </summary>
  <DisplayName("Value, %")> _
Public Property Percent As double
  ''' <summary>
  ''' The output parameter. It contains text messages on the processed orders.
  ''' </summary>
  Public ReadOnly Property ProcessedOrdersLog As List(Of String)
    Get
      Return If(__processedOrdersLog, (__processedOrdersLog = New List(Of String)()))
    End Get
  End Property
End Class

The example demonstrates a number of attributes with default values. It is done in order to demonstrate wide possibilities of using attributes.

Sometimes, they may be omitted in certain applications. To learn more about BO attributes, refer to the following topics:

All public properties of the BO class are interpreted as parameters of a Business Operation. Some of them are initialized by the framework prior to the execution of this BO. Deeper examination of the properties used in the example follows below.

The public ICollection<Order> Orders property.

Due to the fact this property is decorated with ContextPropertyAttribute, the framework interprets it as the context of the BO availability.

In case the context property type is not a collection, the context BO is called "single Business Operation". Such BO can be applied to one object only. If the user selects several objects in the List View, then single BO become unavailable for starting from the UI. At the time of executing a BO, the framework initializes the context property using the reference to the current object.

The type of the context property may be a generic collection (as was shown in the example above). The "Order" object is a parameter of a generic type. Such BO is called "list Business Operation". The generic collection type can be either abstract (e.g. ICollection<T>) or specific (e.g. List<T>). All supported types are listed in the description of the CollectionCreatorFactory class. The framework creates an instance of the suitable collection class, populates it with references to the selected objects (or the current object if no objects are selected), and initializes the context property of the BO with this newly created class instance.

Xafari supplies the eXtensionsFramework (XF) technology to design the application business model. Context-dependent BO should work correctly with all business objects based on this technology.

The situation when ContextPropertyAttribute is concurrently applied to several properties is considered incorrect (the behavior of the framework is not determined for such cases). It should cause no compilation errors or execution errors, but the framework may use arbitrary properties as the context.

All BO are represented in the Application|Xafari|BusinessOperations|<BusinessOperation item> node of the Application Model. The context is represented by a number of properties: ContextDataType, ContextProperty, ContextTypeMatchMode, ContextObjectsCriteria, and ContextObjectsCriteriaMode (see IModelBusinessOperationContext).

The public double Percent property.

This property is declared in the BO class and has a public setter. The framework sees this property as the input parameters of a certain Business Operation. The framework generates a Detail View for parameters input before starting the BO. The Detail View displays Property Editors for all input parameters. The Detail View does not display context properties, the IBusinessOperationManaged.Process property, and properties without a public setter. To generate the Detail View, the framework uses the object of the BODynamicPropertiesObject class (which is a heir of the DynamicPropertiesObject class).

The Detail View identifier is generated based on the BODPO_InputParameters_BusinessOperationId_DetailView template, where BusinessOperationId is the identifier of the BO. Sometimes, the View Id may be required in own controllers for View customizations. To get the View Id in the code, use the BOMethodRunner.GetInputParametersDetailViewId static method.

All parameters of each BO are listed in the Application|Xafari|BusinessOperations|<BusinessOperation item>|Parameters node of the Application Model (see IModelBusinessOperation and IModelBusinessOperationParameter).

To learn more about attributes for Business Operation properties, refer to the Business Operation Properties Attributes topic.