InfoConnect API Guide
Walkthrough / Other Automation Tasks / Work With Multiple Sessions
Work With Multiple Sessions

You can work with more than one session at a time in InfoConnect. This sample shows how to get text from one session and put it into another session.

To copy text from one session to another 

  1. 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
    Attachmate.Reflection.Framework
    Attachmate.Reflection.Emulation.IbmHosts
    Attachmate.Reflection.Emulation.OpenSystems

  2. Replace all the code in the Program.cs file with the following code for the terminal you are using. This code sets up a property for the text that is copied from one session to another. It also creates two sessions and creates event handlers (and a method for Open Systems) to navigate through each session.
    Add property and create terminals
    Copy Code
    using System;
    using System.Threading;
    using Attachmate.Reflection.Framework;
    using Attachmate.Reflection.Emulation.IbmHosts;
    using Attachmate.Reflection.UserInterface;
    
    namespace WorkWithSessions
    {
        class MultipleSessions
        {
            //The value to copy between screens
            static private string _textToCopy = string.Empty;
            static public string TextToCopy
            {
                get
                {
                    return _textToCopy;
                }
                set
                {
                    _textToCopy = value;
                }
            }
    
        
            static void Main(string[] args)
            {
                //Start a visible instance of InfoConnect or get the instance running at the given channel name
                Application app = MyReflection.CreateApplication("myWorkspace", true);
    
                //Create an IBM 5250 terminal control
                IIbmTerminal terminalA = (IIbmTerminal)app.CreateControl(new Guid("{AF03A446-F278-4624-B9EF-C896DF2CA1CA}"));
    
                //Create an IBM 3270 terminal control
                IIbmTerminal terminalB = (IIbmTerminal)app.CreateControl(new Guid("{09E5A1B4-0BA6-4546-A27D-FE4762B7ACE1}"));
             
                //Get the screens for each terminal
                IIbmScreen screenA = terminalA.Screen;
                IIbmScreen screenB = terminalB.Screen;
    
                //Use the host addresses for the InfoConnect onboard demos
                terminalA.HostAddress = "demo:ibm5250.sim";
                terminalB.HostAddress = "demo:ibm3270.sim";
    
                //Make the sessions visible                
                IFrame frame = (IFrame)app.GetObject("Frame");
                frame.CreateView(terminalA);
                frame.CreateView(terminalB);
    
                //Create event handlers to handle navigation for each screen
                screenA.NewScreenReady += screenA_NewScreenReady;
                screenB.NewScreenReady += screenB_NewScreenReady;
    
                Console.ReadKey();
            }
        }
    }
    
  3. Add the code to navigate through the first session and get some text.  
    Navigate to screen in first session and get text
    Copy Code
    //Navigate to the appropriate screen and set the text for the TextToCopy property
    static void screenA_NewScreenReady(object sender, EventArgs e)
    {
        IIbmScreen screen = (IIbmScreen)sender;
    
        //Get text strings for screen positions and compare these strings to
        //known values for each screen to determine which screen the program is on 
        string ScreenID1 = screen.GetText(1, 36, 4);
        string ScreenID2 = screen.GetText(1, 40, 4);
        string ScreenID3 = screen.GetText(1, 25, 13);
        if (ScreenID1 == "Sign")
        {
            screen.SendControlKey(ControlKeyCode.Transmit);
        }
        if (ScreenID2 == "Main")
        {
            screen.SendKeys("kayak");
            screen.SendControlKey(ControlKeyCode.Transmit);
        }
        if (ScreenID3 == "INTERNATIONAL")
        {
                   
            //Get the text and assign it to the TextToCopy property
            TextToCopy = screen.GetText(1, 39, 5);
        }
    }
    
  4. Add the code to navigate through the second session and enter the text.  
    Navigate to screen in second session and enter text
    Copy Code
    //Navigate to the appropriate screen and put the text in the TextToCopy property on that screen
    static void screenB_NewScreenReady(object sender, EventArgs e)
    {
        IIbmScreen screen = (IIbmScreen)sender;
    
        //Get text strings for screen positions and compare these strings to
        //known values for each screen to determine which screen the program is on 
        string ScreenID1 = screen.GetText(1,2,3);
        string ScreenID2 = screen.GetText(1, 1, 5);
        string ScreenID3 = screen.GetText(2, 2, 6);
        string ScreenID4 = screen.GetText(2, 2, 7);
    
        if (ScreenID1 == "ATM") {
            screen.SendControlKey(ControlKeyCode.Transmit);
        }
        if (ScreenID2 == "LOGON")
        {
            screen.SendKeys("ISPF");
            screen.SendControlKey(ControlKeyCode.Transmit);
        }
        if (ScreenID3 == "OPTION")
        {
            screen.SendKeys("1");
            screen.SendControlKey(ControlKeyCode.Transmit);
        }
        if (ScreenID4 == "COMMAND")
        {
            //Make sure the text is retrieved from the other screen
            while (string.IsNullOrEmpty(TextToCopy))
            {                     
                System.Threading.Thread.Sleep(500);
            } 
    
            //Put the text in field and reset the TextToCopy property
            screen.PutText(TextToCopy, 5, 18);
            TextToCopy = string.Empty;
        }
         
    }
    

To test this project

  1. If you are using an Open Systems terminal, open InfoConnect and create a new VT session. Then enter "demo:UNIX" in the IP/Address box and save the session as demoSession.rdox.
  2. In Visual Studio, press F5 to run the project.
  3. Verify that the two sessions open and that the text is retrieved from one session and put into the other.