//This sample gets all of the unnamed terminal controls running in an instance of Reflection.
//Before you run this sample, make sure at least one session 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;
using Attachmate.Reflection.Emulation.OpenSystems;
namespace ConnectToASession
{
class Program
{
static void Main(string[] args)
{
//Get a handle to the first Application instance 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.ActiveApplication;
//Get all of the terminal controls that are not named
object[] terminals = app.GetControlsByName("");
//Check to make sure at least one session is running.
if (terminals != null && terminals.Length > 0)
{
//Find terminals based on terminal type and host address
foreach (Object terminal in terminals)
{
if (terminal.ToString().Contains("Ibm"))
{
IIbmTerminal terminalIBM = (IIbmTerminal)terminal;
//Find specific terminals based on host address
//Then get connection status, get text from the screen, or perform other tasks
Console.WriteLine(terminalIBM.HostAddress);
}
if (terminal.ToString().Contains("OpenSystems"))
{
ITerminal terminalOS = (ITerminal)terminal;
IConnectionSettingsTelnet conn = terminalOS.ConnectionSettings as IConnectionSettingsTelnet;
if (conn != null)
{
Console.WriteLine(((terminalOS.ConnectionSettings as IConnectionSettingsTelnet).HostAddress));
}
}
}
}
Console.ReadLine();
}
}
}