InfoConnect API Guide
Get Started / Create an Invisible Session
In This Topic
    Create an Invisible Session
    In This Topic

    You can create or open a session that runs without displaying the workspace and session.

    This sample opens a session document and makes the workspace invisible. Data is copied from the screen and displayed in the console.

    To create an invisible session

    1. Open the InfoConnect workspace and create a demo session as follows:

      If you are using IBM, create an IBM3270 session with a host name of "demo:ibm3270.sim" and save the session as demoSession.rd3x in the default folder (...\myDocuments\Micro Focus\InfoConnect.)

      If you are using Open Systems, create a VT session with a host name of "demo:UNIX" and save the session as demoSession.rdox in the default folder.

    2. In InfoConnect, create a session document and save it as "demoSession" in the default folder. (The default folder is ..\myDocuments\Micro Focus\InfoConnect.)
    3. In Visual Studio, create a new Console Application project and add references for the following InfoConnect assemblies. (Depending on your version of Visual Studio, these can be found either on the .NET tab or under Assemblies | Extensions.)
      Attachmate.Reflection.Framework
      Attachmate.Reflection.Emulation.IbmHosts
      Attachmate.Reflection.Emulation.OpenSystems
      Attachmate.Reflection
    4. Replace all the code in the Program.cs file with the following code for the terminal you are using.
      Create an invisible session
      Copy Code
      using System;
      using System.Collections.Generic;
      using System.Text;
      using Attachmate.Reflection.Framework;
      using Attachmate.Reflection.Emulation.IbmHosts;
      using Attachmate.Reflection.UserInterface;
      
      namespace CreateSessionFromExistingSessionFile
      {
          class Program
          {
              static void Main(string[] args)
              {
                  //Start an invisible instance of InfoConnect or get the instance running at the given channel name 
                  Application app = MyReflection.CreateApplication("myWorkspace", false);
      
                  //Create a terminal from the session document file
                  string sessionPath = Environment.GetEnvironmentVariable("USERPROFILE") + @"\Documents\Micro Focus\InfoConnect\demoSession.rd3x";
                  IIbmTerminal terminal = (IIbmTerminal)app.CreateControl(sessionPath);
      
                  //Create a view for the session
                  IFrame frame = (IFrame)app.GetObject("Frame");
                  frame.CreateView(terminal);
      
                  //Get a handle to the screen. Then wait until it is ready and get the maximum columns and rows
                  IIbmScreen screen = terminal.Screen;
                  screen.WaitForHostSettle(3000, 2000);
                  int maxCols = screen.Columns;
                  int maxRows = screen.Rows;
      
                  //Get the text on the screen and write it to the Console.
                  string text = screen.GetTextEx(1, 1, maxRows, maxCols, GetTextArea.Block, GetTextWrap.On, GetTextAttr.Any, GetTextFlags.None);
                  Console.WriteLine(text);
      
      
                  //Close InfoConnect 
                  app.Close(ApplicationCloseOption.CloseNoSave);
      
                  Console.ReadLine();
      
              }
          }
      }
      
      
      
      
      

                                                                                        

      Example Title
      Copy Code
      using System;
      using System.Collections.Generic;
      using System.Text;
      using Attachmate.Reflection.Framework;
      using Attachmate.Reflection.Emulation.OpenSystems;
      using Attachmate.Reflection.UserInterface;
      namespace CreateSessionFromExistingSessionFile
      {
          class Program
          {
              static void Main(string[] args)
              {
                  //Start an invisible instance of InfoConnect or get the instance running at the given channel name
                  Application app = MyReflection.CreateApplication("myWorkspace", false);
      
                  //Create a terminal from the session document file
                  string sessionPath = Environment.GetEnvironmentVariable("USERPROFILE") + @"\Documents\Micro Focus\InfoConnect\demoSession.rdox";
                  ITerminal terminal = (ITerminal)app.CreateControl(sessionPath);
      
                  //Create a view for the session
                  IFrame frame = (IFrame)app.GetObject("Frame");
                  frame.CreateView(terminal);
      
                  //Get a handle to the screen and wait until it is ready
                  IScreen screen = terminal.Screen;
                  screen.WaitForHostSettle(6000, 3000);
      
                  //Get the text in the display memory and write it to the Console
                  int maxrows = screen.DisplayRows;
                  int maxcols = screen.DisplayColumns;
                  string text = screen.GetText(1, 1, maxrows, maxcols);
                  Console.WriteLine(text);
      
                  //Close InfoConnect
                  app.Close(ApplicationCloseOption.CloseNoSave);
      
                  Console.ReadLine();
              }
          }
      }
      
       
      
                                              
      

                                          

    To test this project

    Press F5 to run the project and verify that the text from the session is displayed in the Console.