Show Contents / Index / Search

Get View and Session (OpenSystems)

using System;

using System.Collections.Generic;

using System.Text;

using Attachmate.Reflection.Framework;

using Attachmate.Reflection.UserInterface;

using Attachmate.Reflection.Emulation.OpenSystems;

 

namespace GetViewAndControlByTitleText

{

  class Program

  {

    static void Main(string[] args)

    {

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

      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 2008 instance.

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

          if (sessionView != null)

          {

            //Get the control embedded in the view.

            ITerminal terminal = (ITerminal)sessionView.Control;

            if (terminal != null)

            {

              IScreen screen = terminal.Screen;

              IConnectionSettingsTelnet conn = (IConnectionSettingsTelnet)terminal.ConnectionSettings;

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

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

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

            }

            else

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

          }

          else

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

        }

        else

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

      }

      else

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

    }

  }

}