//This sample gets the Terminal control of a running session.
//Before you run this sample, make sure the session used in GetControlsByFilePath()
//is running in a Reflection workspace. If more than one instance of Reflection is running,
//the session must be running in the first instance that was started.
using System;
using System.Collections.Generic;
using System.Text;
using Attachmate.Reflection.Framework;
using Attachmate.Reflection.Emulation.IbmHosts;
namespace ConnectToASession
{
class Program
{
static void Main(string[] args)
{
//Get a handle to an application that represents the first instance of Reflection started manually.
//For production code, use a try catch block here to handle a System Application Exception thrown
//if the app isn't running.
Application app = MyReflection.CreateApplication();
//Get the terminal from the session document file path.
string sessionPath = Environment.GetEnvironmentVariable("USERPROFILE") + @"\Documents\Micro Focus\Reflection\demoSession.rd3x";
object[] terminals = app.GetControlsByFilePath(sessionPath);
//Check to make sure the session is running.
if (terminals != null && terminals.Length > 0)
{
//Get a screen and then get some text from the screen.
IIbmTerminal terminal = (IIbmTerminal)terminals[0];
IIbmScreen screen = terminal.Screen;
string text = screen.GetText(18, 2, 48);
Console.WriteLine(text);
}
else
Console.WriteLine("No such control exists. Check to make sure that the session from the file is running.");
}
}
}