Access Layer API – Basic Operations

The Access Layer API contains a number of interfaces and classes that are required to interact with the runtime system. The main components are as follows:

The DataHandler property of the IConnection interface is an instance of IRtConnection and provides a mechanism to exchange data between the client and the host application.

The basic flow of operations when developing a client application is as follows:

  1. Instantiate a Connection object by using the static ConnectionFactory class.

    This returns an instance of a Connection object when calling the Create() method.

  2. Create a new ConnectionDetails object and set its properties with information about how to connect to the host application.

  3. Perform a Connect() call on the Connection object by passing in the ConnectionDetails.

    The Connect() method returns a TransmissionObject from which you can determine the status of the connection and the current DataModel (if the system returns a fireup ispec).

  4. Populate the DataModel with new information by setting its properties.

  5. Use the DataHandler object to send the DataModel details to the runtime system, with either the Transmit() or TransmitAsync() method.

  6. The Transmit() or TransmitAsync() method returns an updated Transmission object that indicates the resulting state of the transaction and provides an updated DataModel, which might be for the same ispec or a new ispec.

    Repeat steps 5 through 6 to perform additional transactions with the runtime system.

  7. Close the connection by using the Connection object, Close() method.

The following code shows an example of these operations:

// Create a new connection to the AB Suite host system
// Use the Access Layer API ConnectionFactory to create an instance of a Connection Interface class

ABSConnection = ConnectionFactory.Create(new Sample.Custom.DataModels.Core.IspecFactory());

// Set up the ConnectionDetails object with information from Web.config 
ConnectionDetails cDetails = new ConnectionDetails()
{
      Host = "localhost",
      IsAnonymous = true,
      System = "Sample,
      ForceLogin = true,
      AssemblyLocation = @"C:\ABSuite\Datamodels",
      LogFolder=@"C:\Temp",
      LogLevel="DEBUG"
};

TransmissionObject trObj = ABSConnection.Connect(cDetails, null);

if (trObj != null && (trObj.State == TransmissionReturnCode.Ok || 
trObj.State == TransmissionReturnCode.OkWithSwitch))
  {
     SessionConnected = true;
     CurrentIspecName = trObj.ObjectClassName;
  }
  else
     SessionConnected = false;

// Create an instance of a PRODModel class. 
PRODModel pModel = (PRODModel) ABSConnection.DataHandler.GetDataModelObject("PROD");
// Populate the PRODModel 
pModel._UserMAINT = "FIR";
// Transmit the PRODModel to the host system
TransmissionObject tObject = ABSConnection.DataHandler.Transmit(pModel);
// Check the return state and whether the current context is for the PROD ispec
if (tObject.State == TransmissionReturnCode.Ok)
{
   // Check the DataModel type in the returned TransmissionObject, 
   // by using the ObjectClassName as the name of the Ispec. If it 
   // is a type of PRODModel, extract the data.
   if  (ABSConnection.DataHandler.GetDataModelType(tObject.ObjectClassName) == typeof(PRODModel))
      {
     // Extract the Data from the PRDOModel object returned by the Connector.
          pModel = (PRODModel)tObject.Datamodel;
          string Name = pModel.NAM;
          string ID = pModel.PRODUCT;
          decimal price = pModel.SELLPRICE;
          Int32 reOrderLevel = pModel.REORDLEV;
      }
  }
   // Close the connection
  ABSConnection.Close();

See Access Layer API Interfaces for a detailed description of each interface, its properties, and events.