Show Contents / Index / Search

Get View and Session (IBM)

//This sample code is intended to illustrate a concept, and it shows only the code that is relevant to that concept.

//It may not meet the security requirements for a specific environment, and it should not be used exactly as shown.

//We recommend that you add security and error-handling code to make your projects more secure and robust.

//Attachmate provides this sample code "AS IS" with no warranties.

 

using System;

using System.Collections.Generic;

using System.Text;

using Attachmate.Reflection.Framework;

using Attachmate.Reflection.UserInterface;

using Attachmate.Reflection.Emulation.IbmHosts;

 

//GetViewAndControlByTitleText gets the view and terminal control of a running session.

//Before you run this sample, open the session used by GetViewByTitleText (in this sample, this is Test.rd3x).

namespace GetViewAndControlByTitleText

{

  class Program

  {

    static void Main(string[] args)

    {

      Attachmate.Reflection.Framework.Application reflectionApplication = MyReflection.CreateApplication();

      if (reflectionApplication != null)

      {

        IView sessionView;

        //Get the Frame object.

        IFrame theFrame = (IFrame)reflectionApplication.GetObject("Frame");

        if (theFrame != null)

        {

          //Get the session view by using the title text. Title text appears on the tab of the loaded session in the running Reflection 2011 instance.

          sessionView = theFrame.GetViewByTitleText("test.rd3x");

          if (sessionView != null)

          {

            //Get the control embedded in the view.

            IIbmTerminal terminal = (IIbmTerminal)sessionView.Control;

            if (terminal != null)

            {

              IIbmScreen screen = terminal.Screen;

              screen.WaitForHostSettle(6000, 3000);

              string text = screen.GetText(18, 2, 48);

              Console.WriteLine("The text at row 18, column 2: " + text);

              Console.WriteLine("The session is connected to: " + terminal.HostAddress);

            }

            else

              Console.WriteLine("Fatal error. Check Reflection 2011 installation.");

          }

          else

            Console.WriteLine("No such view is open in Reflection 2011. Check the view's title text.");

        }

        else

          Console.WriteLine("Fatal error. Check Reflection 2011 installation.");

      }

      else

        Console.WriteLine("Failed to get Application object.");

    }

  }

}