Reflection 2014 .NET API Guide
Create a New Session

This sample program creates a completely new host session without an existing Reflection 2014 session file.

The session is created by getting a control object, which contains only the data of a session and, by itself, isn't visible. (To make a session visible, you must also create a View object.)

To create a new session

  1. Start Reflection 2014.
  2. In Visual Studio, create a new Console Application project.
  3. In the New Project dialog box, type Create New Session in the Name box.
  4. Select the Create directory for solution box, click Browse to select your API projects folder (for example, C:\MyProjects), and then click OK.
  5. In Solution Explorer, add the class assemblies. (For instructions, see Create an API Project.)
  6. 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.Emulation.IbmHosts;
    
    namespace GetStartedConsole
    
    {
    
      class Program
        {
    
          static void Main(string[] args)
    
          {
    
    
            Attachmate.Reflection.Framework.Application reflectionApplication = MyReflection.CreateApplication("myWorkspace", true);
    
    
            if (reflectionApplication != null)
            {
    
              //For a 3270 session
    
              IIbmTerminal terminal = (IIbmTerminal)reflectionApplication.CreateControl(new Guid("{09E5A1B4-0BA6-4546-A27D-FE4762B7ACE1}"));
    
    
              //For a 5250 session
              //IIbmTerminal terminal = (IIbmTerminal)reflectionApplication.CreateControl(new Guid("{AF03A446-F278-4624-B9EF-C896DF2CA1CA}"));
    
              if (terminal != null)
    
              {
    
                //Specify the host name or IP address.
    
                terminal.HostAddress = "[MyHost]";
    
                terminal.Connect();
    
                //Alternatively, use the 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("Failed to create the control.");
            }
    
            else
    
              Console.WriteLine("Failed to get Application object.");
          }
    
        }
    
    }
    
                               
    using System;
    using System.Collections.Generic;
    using System.Text;
    using Attachmate.Reflection.Framework;
    using Attachmate.Reflection.Emulation.OpenSystems;
    
     
    namespace GetStartedConsole
    
    {
    
      class Program
      {
    
        static void Main(string[] args)
        {
    
    
          Attachmate.Reflection.Framework.Application reflectionApplication = MyReflection.CreateApplication("myWorkspace", true);
    
    
          if (reflectionApplication != null)
          {
    
    
            //Create a UNIX or OpenVMS session document.
            ITerminal terminal = (ITerminal)reflectionApplication.CreateControl(new Guid("{BE835A80-CAB2-40d2-AFC0-6848E486BF58}"));
    
    
            if (terminal != null)
    
            {
    
              //Specify the host address.
              IConnectionSettingsTelnet conn = (IConnectionSettingsTelnet)terminal.ConnectionSettings;
              conn.HostAddress = "[host_address]";
              terminal.Connect();
    
    
              //Alternatively, 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("Failed to create the control.");
    
          }
    
          else
    
            Console.WriteLine("Failed to get Application object.");
    
    
        }
    
      }
    
    }
    
  7. In Visual Studio, paste the code to the Program.cs tab, replacing all existing code.
  8. Note the following operations in this program (examples below are for IBM hosts).

    Get an application object:

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

    Create a control object for a 3270 terminal session:

    IIbmTerminal terminal = (IIbmTerminal)reflectionApplication.CreateControl(new Guid("{09E5A1B4-0BA6-4546-A27D-FE4762B7ACE1}"));

    Connect to the host:

    terminal.HostAddress = "[MyHost]";

    terminal.Connect();

    Wait for the host screen to settle:

    screen.WaitForHostSettle(6000, 3000);

    Get text from the session screen (row 18, column 2, text string length 48):

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

    Write the text to a console window:

    Console.WriteLine(text);

  9. Build the application (Build > Rebuild Solution) and then run it (Debug > Start Without Debugging).

    A console window should appear, displaying text from a session.