Connecting to the AB Suite System

A connection to the AB Suite system is established when the ASP.NET session is initiated on the request received from the browser. This event is captured in the Session.Start() method and can be customized in the Global.asax.cs file as shown in the following code:

protected void Session_Start()
    {
        // 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
      IConnection ABSConnection = 
      ConnectionFactory.Create(new Contacts.CF_MVC.DataModels.Core.IspecFactory(), 
      level: "DEBUG", logPath: @"C:\Temp");
 
// Set up the ConnectionDetails object with the required information
// to connect to the host system
        ConnectionDetails cDetails = new ConnectionDetails()
        {
            Host = "localhost",
            IsAnonymous = true, 
            System = "Contacts",
            ForceLogin = true,
            LogFolder = @"C:\Temp",
            LogLevel = "DEBUG"
        };
 
   // Local variables
        bool SessionConnected = false;
        string CurrentIspecName = "";
       
// Call the Access Layer API Connect() method to establish a session
// with the host application. A TransmissionObject is returned to 
// provide information about the connection attempt.
        TransmissionObject trObj = ABSConnection.Connect(cDetails, null);
   
   // Check the TransmissionObject state and process accordingly
        if (trObj != null && 
            (trObj.State == TransmissionReturnCode.Ok 
             || trObj.State == TransmissionReturnCode.OkWithSwitch))
        {
            SessionConnected = true;
            CurrentIspecName = trObj.ObjectClassName;
            // Store Current Ispec Name and Current Transmission 
            // Object in Session State:
            Session["CurrentIspecName"] = CurrentIspecName;
            Session["CurrentTO"] = trObj;
            // Store the Connection object in Session State
            Session["ABSConnection"] = ABSConnection;
        }
        else
            SessionConnected = false;

        // Store SessionConnected state in Session State:
        Session["SessionConnected"] = SessionConnected;

    }

As shown in the code, the main aspects of session establishment involves the following:

  1. Obtain a Connection object from the Access Layer API ConnectionFactory.

  2. Create a ConnectionDetails object with information about connecting to the runtime system.

  3. Call the Connect() method by passing the ConnectionDetails object.

  4. Check the returned TransmissionObject for success or failure of connection.

  5. Store the current session information in SessionState for use while this session is active.

The HomeController Actions can now use the Connector object by retrieving it from SessionState.