BusinessProcess Class

Used to iterate rows of entities and perform business logic operations, without user interaction.

Definition

Namespace: Firefly.Box
Assembly: Firefly.Box (in Firefly.Box.dll) Version: debug-master-v:33791
C#
public sealed class BusinessProcess : ITask
Inheritance
Object    BusinessProcess
Implements
ITask

Remarks

The business process is executed using the Run method. See the Run method for a detailed explanation of the event flow for the BusinessProcess

Example

This example demonstrates several examples of using a BusinessProcess
This example is in the form of Unit Tests. It references the NUnit framework. This framework can be downloaded from www.NUnit.org. For more information about unit testing visit: www.NUnit.org.
This example is based on test data. The code for the entities included in this test data can be found in the documentation of Entity
C#
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using Firefly.Box;
using Firefly.Box.Testing;

namespace TestFirefly.Box.Documentation
{
    [TestFixture]
    public class DemoBusinessProcess
    {
        [Test]
        public void IterateAllRows()
        {
            var employees = new Pubs.Employees();
            employees.InitializeWithTestData();// Insert test data to the table

            var bp = new BusinessProcess
                         {
                             From = employees,
                             Activity = Activities.Update // The default activity
                         };
            int numberOfEmployeesWithoutMiddleInitials = 0;
            bp.ForEachRow(() =>
                              {
                                  if (employees.MiddleInitial == "")
                                      numberOfEmployeesWithoutMiddleInitials++;
                              });
            numberOfEmployeesWithoutMiddleInitials.ShouldBe(10);//Checks that there are 10 employees in the test data without a middle initial
        }
        [Test]
        public void DeleteEmployeesWithJob5()
        {

            var employees = new Pubs.Employees();
            employees.InitializeWithTestData();// Insert test data to the table
            employees.CountRows().ShouldBe(43);// Verifies that the test data has 43 rows

            var bp = new BusinessProcess
                         {
                             From = employees,
                             Activity = Activities.Delete
                         };
            bp.Where.Add(employees.JobId.IsEqualTo(5));
            bp.Run();

            employees.CountRows().ShouldBe(36);// Verifies that after the delete, only 36 rows remain
        }
        [Test]
        public void InsertAnEmployee()
        {
            var employees = new Pubs.Employees();
            employees.InitializeWithTestData();// Insert test data to the table
            employees.CountRows().ShouldBe(43); // Verifies that the test data has 43 rows

            var bp = new BusinessProcess
                         {
                             From = employees,
                             Activity = Activities.Insert
                         };
            bp.ForFirstRow(() =>
                               {
                                   employees.Id.Value = "ID-1234";
                                   employees.FirstName.Value = "John";
                                   employees.LastName.Value = "Doe";
                               });
            employees.CountRows().ShouldBe(44);// Verifies that after the insert, there are 44 rows in the test data
        }
    }
}

Constructors

BusinessProcessInitializes a new instance of the BusinessProcess class.
BusinessProcess(BusinessProcessAdvancedSettings)Initializes a new instance of the BusinessProcess class.

Properties

Activity Determines the main activity to be performed in this BusinessProcess
AllowUserAbort Gets or sets the value determining if the BusinessProcess will listen to certain inputs from the user that will cause it to terminate.
AutoCompute 
BindEntireDataviewRowBeforeWhereExpression 
ColumnsGets the columns that are used in this BusinessProcess
Counter Returns the number of cycles started so far.
CurrentHandledCommand Return the currently handled command
CurrentHandledControl Return the currently handled control
CurrentHandledKey Return the currently handled key combination
EntitiesGets entities that are associated to this BusinessProcess by the From property and Relations property
FromDetermines the Entity who's rows the BusinessProcess will perform it's iteration on.
GroupsGets the value determining the BusinessProcess's groups
HandlersGets the BusinessProcess's handlers
InTransactionGets the value determining if a transaction is currently open.
KeepViewVisibleAfterExitGets or sets the value determining if the BusinessProcess's form should remain visible after the BusinessProcess exits.
ModuleGets or sets the value determining the ModuleController to whom this BusinessProcess is associated
NonDbWhere This Where will always be evaluated in memory and may have performance implications
OrderByGets or sets the value determining order in which the rows are ordered
RelationsGet this BusinessProcess relations
ReloadRowBeforeGroupEnter 
RowChanged Indicates if the current row has changed.
RowLockingGets or sets the value determining the BusinessProcess's row locking strategy
ShowViewGets or sets the value determining if the view specified in the View property should be displayed when this BusinessProcess is executed.
TitleGets or sets the BusinessProcess's title
TransactionScopeGets or sets the value determining the BusinessProcess's transaction scope
TransactionScopeGroup 
TransactionType 
UserInterfaceRefreshIntervalsets the value determining the interval in milliseconds for the user interface refresh
UserInterfaceRefreshRowsInterval 
View Determines the form to be displayed while this BusinessProcess is running
WhereGets the value determining the filter that will be applied on the rows of this BusinessProcess.

Methods

AddAllColumnsAdds all the columns of the Entity determined in the From property, and all the entities specified in the Relations property to the Columns property collection.
BindKeepViewVisibleAfterExitSets an expression that will determine the value of the KeepViewVisibleAfterExit property.
DeleteRowAfterLeavingItIfSets an expression that determines if the current row will be deleted once left.
DeltaOfReturns The delta between the value of expression before the EnterRow event, and the current value of expression
EqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
ExitInstructs the BusinessProcess to exit.
Exit(ExitTiming)Instructs the BusinessProcess to exit.
Exit(ExitTiming, FuncBoolean)Instructs the BusinessProcess to exit.
ForEachRow(Action) Performs the specified action on each row that matches the Where property filter.
ForEachRow(FilterBase, Action) Performs the specified action on each row that matches the Where property filter.
ForFirstRow(Action)Performs the specified action on the first row that matches the Where property filter.
ForFirstRow(FilterBase, Action)Performs the specified action on the first row that matches the Where property filter.
Get(FuncNumber) 
Get(FuncText) 
Get(FuncNumber, FilterBase) 
Get(FuncText, FilterBase) 
GetT(TypedColumnBaseT) 
GetT(TypedColumnBaseT, FilterBase) 
GetHashCodeServes as the default hash function.
(Inherited from Object)
GetTypeGets the Type of the current instance.
(Inherited from Object)
Invoke(Action)Invokes a action that will be handled by an Handler.
Invoke(CommandWithArgs)Invokes a command that will be handled by an Handler.
Invoke(Command, Object)Invokes a command that will be handled by an Handler.
Invoke(Keys, Object)Invokes a keyCombination that will be handled by an Handler.
Invoke(String, Object)Invokes a customCommandKey that will be handled by an Handler.
InvokeT(Command, ArrayColumnT) 
InvokeT(Keys, ArrayColumnT) 
InvokeT(String, ArrayColumnT) 
LockCurrentRowLocks the current row for the Entity specified in the From property , and all the entities specified in the Relations property collection.
MarkRowAsChanged 
PerformCompute 
Raise(CommandWithArgs)Raises a command that will be handled by an Handler.
Raise(Command, Object)Raises a command that will be handled by an Handler.
Raise(Keys, Object)Raises a keyCombination that will be handled by an Handler.
Raise(String, Object)Raises a customCommandKey that will be handled by an Handler.
RaiseT(Command, ArrayColumnT) 
RaiseT(Keys, ArrayColumnT) 
RaiseT(String, ArrayColumnT) 
ReadAllRows Used for quick, read-only pass over all the rows of the BusinessProcess.
Run Runs the BusinessProcess
Sum(FuncNumber) 
Sum(NumberColumn) 
Sum(FuncNumber, FilterBase) 
Sum(NumberColumn, FilterBase) 
ToStringReturns a string that represents the current object.
(Overrides ObjectToString)

Events

AbortRowOccurred 
AfterSavingRow 
BeforeExit 
DatabaseErrorOccurredOccurs when a database error occurs and after all the DatabaseErrorHandler processed the error.
EndOccurs when the BusinessProcess ends. Raised once for each Run method. Preserves the last row data.
EnterRowOccurs when a row is entered by this BusinessProcess and after that row was loaded from the database.
LeaveRowOccurs when A Row is left, and before it is saved to the database.
LoadOccurs when the BusinessProcess is executed, before the Start event and before the database query is constructed. Raised once for each Run method.
PreviewDatabaseErrorOccurs when a database error occurs and before all the DatabaseErrorHandler process the error.
ProcessingCommand 
SavingRow Occurs when the BusinessProcess is about to save the row
StartOccurs when starts and after the Load event. Raised once for each Run method.

See Also