Reflection 2014 .NET API Guide
Build and Test a Program

Complete this task to ensure that you can successfully build a sample program using the Reflection API. In the sample program provided, the code gets a control object from an existing session (identified by its file path) and displays data from that session in a Windows console box.

To create the test project

  1. Start Reflection, create a session document, and connect to the host.
  2. Name and save the session document to a trusted location.
  3. Open the project you created in "Create an API Project."
  4. 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)
            {
    
    
                
                
                
                
                
                
                
                //GettingStartedConsole 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.
    
                Attachmate.Reflection.Framework.Application reflectionApplication = MyReflection.CreateApplication("myWorkspace", true);
    
                if (reflectionApplication != null)
                {
                    object[] terminals = reflectionApplication.GetControlsByFilePath(@"C:\Users\mikebra\Documents\Attachmate\Reflection\gettingStartedSession.rd3x");
                   // object[] terminals = reflectionApplication.GetControlsByFilePath(@"C:\Users\mikebra\Documents\Attachmate\Reflection\demo5250.rd5x");
    
                    Console.WriteLine(terminals.Length);
                    if (terminals != null && terminals.Length > 0)
                    {
                        IIbmTerminal terminal = (IIbmTerminal)terminals[0];
                        IIbmScreen screen = terminal.Screen;
                        string text = screen.GetText(18, 2, 48);
                        Console.WriteLine(text);
    
                        
                        Console.WriteLine(terminal.CmdPrompt);
    
                        //Attach the event handler to the IbmTerminal object's CreditCardRecognized event,
                        //where ibmTerminal is an instance of IbmTerminal.
    
                    }
    
                    else
                        Console.WriteLine("No such control exists. Check to make sure that the session from the file is running.");
                }
    
                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)
            {
    
                //GettingStartedConsole 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.
                Attachmate.Reflection.Framework.Application reflectionApplication = MyReflection.CreateApplication("myWorkspace", true);
    
                if (reflectionApplication != null)
                {
                    object[] terminals = reflectionApplication.GetControlsByFilePath(@"C:\Users\[user name]\Documents\Attachmate\Reflection\[session filename]");
    
                    if (terminals != null && terminals.Length > 0)
                    {
                        ITerminal terminal = (ITerminal)terminals[0];
                        IScreen 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.");
    
                }
    
                else
    
                    Console.WriteLine("Failed to get Application object.");
    
            }
    
        }
    
    }
    
                                    
  5. In Visual Studio, paste the code to the Program.cs tab, replacing all existing code.
  6. 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.
  7. Build the application (Build > Rebuild Solution) and then run it (Debug > Start Without Debugging).

    If the build is successful, a console box opens with the text "Press any key to continue..." The console should also include extracted text from the host screen.

    If the console doesn't include extracted text, the row and column of the screen that you specified contained no text. Change the row and column values to indicate an area of the host screen that contains text. In the following example, the row and column values appear as "18" and "2" respectively:

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