Show Contents / Index / Search

Create New Session (OpenSystems)

//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.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.");

    }

  }

}