Reflection 2014 .NET API Guide
Get a View and its Session Using Title Text

This sample program gets both the View object and the embedded Control object for a session by referencing the title text of the View. For a list of methods by which you can identify View objects, see Getting Terminal and View Objects.

 

To create a view using its title text

  1. Start Reflection.
  2. Create a session document, name it test , and connect it to the host.
  3. In Visual Studio, create a new Console Application project.
  4. In the New Project dialog box, type Get View and Session in the Name box.
  5. Select the Create directory for solution box, click Browse to select your API projects folder (for example, C:\MyProjects), and then click OK.
  6. In Solution Explorer, add the class assemblies. (For instructions, see Create an API Project.)
  7. Copy the code from one of the following programs:
    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 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 2014 installation.");
              }
              else
                Console.WriteLine("No such view is open in Reflection 2014. Check the view's title text.");
            }
            else
              Console.WriteLine("Fatal error. Check Reflection 2014 installation.");
          }
          else
            Console.WriteLine("Failed to get Application object.");
        }
      }
    }
    
    using System;
    using System.Collections.Generic;
    using System.Text;
    using Attachmate.Reflection.Framework;
    using Attachmate.Reflection.UserInterface;
    using Attachmate.Reflection.Emulation.OpenSystems;
     
    //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.rdox).
    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 2014 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 2014 installation.");
              }
              else
                Console.WriteLine("No such view is open in Reflection 2014. Check the view's title text.");
            }
            else
              Console.WriteLine("Fatal error. Check Reflection 2014 installation.");
          }
          else
            Console.WriteLine("Failed to get Application object.");
        }
      }
    }
    
  8. In Visual Studio, paste the code to the Program.cs tab, replacing all existing code.
  9. In the code, find the following line:

    sessionView=theFrame.GetViewByTitleText("");

  10. In the quotation marks, type the filename and extension of the session document that you created in step 2 (for example, test.rdox), making sure to match the letter case.
  11. Build the application (Build > Rebuild Solution) and then run it (Debug > Start Without Debugging).

    A Windows console box appears with a line of text extracted from the host screen, and the following text: "The session is connected to: the_host_address" and "Press any key to continue….."

  12. To terminate the application, press any key.