Reflection 2014 .NET API Guide
Make a Session Visible in a View

Make a Session Visible in a View

In this task, you'll add a View object (session view) to a control object to make a session visible. View and Frame objects provide Reflection user interface elements to a custom application. You must create a control object (that is, a terminal session) before you can add a View object.

Initially, the name property of a View object is empty so that you have the option to set your own identifying string. For a list of the different methods by which you can identify (and get) View objects, see Getting Terminal and View Objects.

To create a view

  1. Start Reflection, create a session document, and connect to the host.
  2. Name and save the session document to a trusted location, and then close it, but leave Reflection running.
  3. In Visual Studio, create a new Console Application project.
  4. In the New Project dialog box, type Make Session Visible 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;
     
    namespace MakeSessionVisible
    {
      class Program
      {
        static void Main(string[] args)
        {
          Attachmate.Reflection.Framework.Application reflectionApplication =MyReflection.CreateApplication("myWorkspace", true);
          if (reflectionApplication != null)
          {
            IIbmTerminal terminal = (IIbmTerminal)reflectionApplication.CreateControl(@"C:\Users\[user name]\Documents\Attachmate\Reflection\[session filename]");
            if (terminal != null)
            {
              terminal.Connect();
              //You can also use AfterConnect event to wait for the connection.
              while (!terminal.IsConnected)
              {
                System.Threading.Thread.Sleep(500);
              }
              IIbmScreen screen = terminal.Screen;
              screen.WaitForHostSettle(6000, 3000);
              string text = screen.GetText(18, 2, 48);
              Console.WriteLine(text);
            }
            else
              Console.WriteLine("Can not create the control. Check the session file path.");
            //This makes a session visible in the Reflection application.
            IView sessionView;
            IFrame theFrame = (IFrame)reflectionApplication.GetObject("Frame");
            if (theFrame != null)
            {
              sessionView = theFrame.CreateView(terminal);
            }
            else
              Console.WriteLine("Fatal error. Check Reflection 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;
     
    namespace MakeSessionVisible
    {
      class Program
      {
        static void Main(string[] args)
        {
          Attachmate.Reflection.Framework.Application reflectionApplication = MyReflection.CreateApplication("myWorkspace", true);
          if (reflectionApplication != null)
          {
            ITerminal terminal = (ITerminal)reflectionApplication.CreateControl(@"C:\Users\[user name]\Documents\Attachmate\Reflection\[session filename]");
            if (terminal != null)
            {
              terminal.Connect();
              //You can also use AfterConnect event to wait for the connection.
              while (!terminal.IsConnected)
              {
                System.Threading.Thread.Sleep(500);
              }
              IScreen screen = terminal.Screen;
              string text = screen.GetText(18, 2, 48);
              Console.WriteLine(text);
            }
            else
              Console.WriteLine("Can not create the control. Check the session file path.");
            //This makes a session visible in the Reflection application.
            IView sessionView;
            IFrame theFrame = (IFrame)reflectionApplication.GetObject("Frame");
            if (theFrame != null)
            {
              sessionView = theFrame.CreateView(terminal);
            }
            else
              Console.WriteLine("Fatal error. Check Reflection 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.

    This program includes the following calls to get View and Frame objects:

    IView sessionView;

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

    sessionView = theFrame.CreateView(terminal);

  9. In the code, change the parameter for reflectionApplication.GetControlsByFilePath to the complete path of your saved session document. Between the quotation marks, type the path exactly as it appears, including the drive letter (for example, C:\), any spaces, and the filename and extension of the session document.
  10. Build the application (Build > Rebuild Solution) and then run it (Debug > Start Without Debugging).

    A new session document should appear in the Reflection workspace.

    Note: To re-create a View object after closing it, you must first re-create the control object that will be associated with the View.