Show Contents / Index / Search

Event Logger (IBM)

//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;

using Attachmate.Reflection.Framework;

using Attachmate.Reflection.Emulation.IbmHosts;

using Attachmate.Reflection.UserInterface;

 

namespace ReflectionEventLogger

{

  class Program

  {

    //Not otherwise defined.

    private const String IBM3270TERMINAL = "{09E5A1B4-0BA6-4546-A27D-FE4762B7ACE1}";

      static void Main(string[] args)

      {

        try

        {

          //Establish necessary Reflection objects.

          Guid rInst = MyReflection.Start();

          //Opens necessary MDI parent.

          Application rApp = MyReflection.CreateApplication();

          IIbmTerminal rTerm = (IIbmTerminal)rApp.CreateControl(new Guid(IBM3270TERMINAL));

          IIbmScreen rScreen = rTerm.Screen;

          IFrame rFrame = (IFrame)rApp.GetObject("Frame");

          IMacro rMacro = rTerm.Macro;

          IOia rOia = rScreen.Oia;

          Attachmate.Reflection.Productivity.ISpellCheck rSpell = rTerm.Productivity.SpellCheck;

          Attachmate.Reflection.Productivity.IRecentTyping rTyping = rTerm.Productivity.RecentTyping;

          Attachmate.Reflection.Productivity.IAutoComplete rAutoComp = rTerm.Productivity.AutoComplete;

          Attachmate.Reflection.Productivity.IAutoExpand rAutoExp = rTerm.Productivity.AutoExpand;

          

          //Set up event handler for IFrame event before creating a new view.

          rFrame.ViewOpened += new ViewEventHandler(rFrame_ViewOpened);

          

          //Create a new view to make the terminal visible in the MDI frame.

          IView rView = rFrame.CreateView(rTerm);

          

          //Hook up events with handlers.

          rView.Closed += new EventHandler(rView_Closed);

          rView.Closing += new CancelableEventHandler(rView_Closing);

          rView.Deselected += new EventHandler(rView_Deselected);

          rView.Selected += new EventHandler(rView_Selected);

          rView.TitleTextChanged += new EventHandler(rView_TitleTextChanged);

          rTerm.AfterConnect += new EventHandler(rTerm_AfterConnect);

          rTerm.AfterDisconnect += new EventHandler(rTerm_AfterDisconnect);

          rTerm.BeforeConnect += new EventHandler(rTerm_BeforeConnect);

          rTerm.BeforeDisconnect += new EventHandler(rTerm_BeforeDisconnect);

          rTerm.Closed += new EventHandler(rTerm_Closed);

          rScreen.AfterSendKeys += new AfterSendKeysEventHandler(rScreen_AfterSendKeys);

          rScreen.BeforeSendControlKey += new BeforeSendControlKeyEventHandler(rScreen_BeforeSendControlKey);

          rScreen.BeforeSendKeys += new BeforeSendKeysEventHandler(rScreen_BeforeSendKeys);

          rScreen.CursorInNewField += new CursorInNewFieldEventHandler(rScreen_CursorInNewField);

          rScreen.KeyboardLocked += new EventHandler(rScreen_KeyboardLocked);

          rScreen.KeyboardUnlocked += new EventHandler(rScreen_KeyboardUnlocked);

          rScreen.NewScreenReady += new EventHandler(rScreen_NewScreenReady);

          rScreen.ScreenChanged += new EventHandler(rScreen_ScreenChanged);

          rMacro.MacroCompleted += new EventHandler(rMacro_MacroCompleted);

          rMacro.MacroStarted += new EventHandler(rMacro_MacroStarted);

          rOia.OiaChanged += new EventHandler(rOia_OiaChanged);

          rSpell.MisspelledWord += new Attachmate.Reflection.Productivity.MisspelledWordEventHandler(rSpell_MisspelledWord);

          rTyping.ListChanged += new EventHandler(rTyping_ListChanged);

          rAutoComp.DictionaryChanged += new EventHandler(rAutoComp_DictionaryChanged);

          rAutoComp.SuggestionAccepted += new Attachmate.Reflection.Productivity.AutoCompleteAcceptedEventHandler(rAutoComp_SuggestionAccepted);

          rAutoExp.AutoExpanded += new Attachmate.Reflection.Productivity.AutoExpandEventHandler(rAutoExp_AutoExpanded);

          rAutoExp.DictionaryChanged += new EventHandler(rAutoExp_DictionaryChanged);

          

          //Connect the session.

          rTerm.HostAddress = "150.215.4.8";

          //Change the IP address to match the IP for your host.

          rTerm.Connect();

          ReturnCode retc = rScreen.WaitForHostSettle(10000, 1000);

          if (retc.Equals(ReturnCode.Timeout) || rTerm.IsConnected == false)

            throw new ApplicationException("Connection failed.");

          else

            Console.Write("Connected to " + rTerm.HostAddress + "\n");

          //You must connect to a session before retrieving an IScreenHistory object or a NullPointerException will occur.

          Attachmate.Reflection.Productivity.IScreenHistory rScrHist = rTerm.Productivity.ScreenHistory;

          rScrHist.ScreenChanged += new EventHandler(rScrHist_ScreenChanged);

          rScrHist.ScreenSelected += new EventHandler(rScrHist_ScreenSelected);

          

          //Wait for input so that events are logged before exiting.

          Console.Write("Press any key to exit ReflectionEventsDemo...\n");

          ConsoleKeyInfo cki = Console.ReadKey();

        }

        catch (ApplicationException ex)

        {

          Console.Write("Uh-oh, " + ex.Message);

        }

      }//Main

      static void rAutoExp_DictionaryChanged(object sender, EventArgs e)

      {

        Console.Write("rAutoExp_DictionaryChanged\n");

      }

      static void rAutoExp_AutoExpanded(object sender, Attachmate.Reflection.Productivity.AutoExpandEventArgs args)

      {

        Console.Write("rAutoExp_AutoExpanded\n");

      }

      static void rAutoComp_SuggestionAccepted(object sender, Attachmate.Reflection.Productivity.AutoCompleteAcceptedEventArgs e)

      {

        Console.Write("rAutoComp_SuggestionAccepted\n");

      }

      static void rAutoComp_DictionaryChanged(object sender, EventArgs e)

      {

        Console.Write("rAutoComp_DictionaryChanged\n");

      }

      static void rTyping_ListChanged(object sender, EventArgs e)

      {

        Console.Write("rTyping_ListChanged\n");

      }

      static void rScrHist_ScreenSelected(object sender, EventArgs e)

      {

        Console.Write("rScrHist_ScreenSelected\n");

      }

      static void rScrHist_ScreenChanged(object sender, EventArgs e)

      {

        Console.Write("rScrHist_ScreenChanged\n");

      }

      static void rSpell_MisspelledWord(object sender, Attachmate.Reflection.Productivity.MisspelledWordEventArgs args)

      {

        Console.Write("rSpell_MisspelledWord\n");

      }

      static void rOia_OiaChanged(object sender, EventArgs e)

      {

        Console.Write("rOia_OiaChanged\n");

      }

      static void rMacro_MacroStarted(object sender, EventArgs e)

      {

        Console.Write("rMacro_MacroStarted\n");

      }

      static void rMacro_MacroCompleted(object sender, EventArgs e)

      {

        Console.Write("rMacro_MacroCompleted\n");

      }

      static void rScreen_ScreenChanged(object sender, EventArgs e)

      {

        Console.Write("rScreen_ScreenChanged\n");

      }

      static void rScreen_NewScreenReady(object sender, EventArgs e)

      {

        Console.Write("rScreen_NewScreenReady\n");

      }

      static void rScreen_KeyboardUnlocked(object sender, EventArgs e)

      {

        Console.Write("rScreen_KeyboardUnlocked\n");

      }

      static void rScreen_KeyboardLocked(object sender, EventArgs e)

      {

        Console.Write("rScreen_KeyboardLocked\n");

      }

      static void rScreen_CursorInNewField(object sender, CursorInNewFieldEventArgs args)

      {

        Console.Write("rScreen_CursorInNewField\n");

      }

      static void rScreen_BeforeSendKeys(object sender, BeforeSendKeysEventArgs args)

      {

        Console.Write("rScreen_BeforeSendKeys\n");

      }

      static void rScreen_BeforeSendControlKey(object sender, BeforeSendControlKeyEventArgs args)

      {

        Console.Write("rScreen_BeforeSendControlKey\n");

      }

      static void rScreen_AfterSendKeys(object sender, AfterSendKeysEventArgs args)

      {

        Console.Write("rScreen_AfterSendKeys\n");

      }

      static void rTerm_Closed(object sender, EventArgs e)

      {

        Console.Write("rTerm_Closed\n");

      }

      static void rTerm_BeforeDisconnect(object sender, EventArgs e)

      {

        Console.Write("rTerm_BeforeDisconnect\n");

      }

      static void rTerm_BeforeConnect(object sender, EventArgs e)

      {

        Console.Write("rTerm_BeforeConnect\n");

      }

      static void rTerm_AfterDisconnect(object sender, EventArgs e)

      {

        Console.Write("rTerm_AfterDisconnect\n");

      }

      static void rTerm_AfterConnect(object sender, EventArgs e)

      {

        Console.Write("rTerm_AfterConnect\n");

      }

      static void rView_TitleTextChanged(object sender, EventArgs e)

      {

        Console.Write("rView_TitleTextChanged\n");

      }

      static void rView_Selected(object sender, EventArgs e)

      {

        Console.Write("rView_Selected\n");

      }

      static void rView_Deselected(object sender, EventArgs e)

      {

        Console.Write("rView_Deselected\n");

      }

      static void rView_Closing(object sender, CancelableEventArgs args)

      {

        Console.Write("rView_Closing\n");

      }

      static void rView_Closed(object sender, EventArgs e)

      {

        Console.Write("rView_Closed\n");

      }

      static void rFrame_ViewOpened(object sender, EventArgs e)

      {

        Console.Write("rFrame_ViewOpened\n");

      }

  }

}