InfoConnect for Unisys
Attachmate.Reflection.Productivity Namespace / IScreenHistory Interface / GetLiveScreenImage Method
Example


In This Topic
    GetLiveScreenImage Method
    In This Topic
    Returns the live screen as an image.
    Syntax
    'Declaration
     
    
    Function GetLiveScreenImage() As Byte()
    'Usage
     
    
    Dim instance As IScreenHistory
    Dim value() As Byte
     
    value = instance.GetLiveScreenImage()
    byte[] GetLiveScreenImage()

    Return Value

    The live screen, in image format.
    Remarks
    Returned images are subject to currently enforced privacy filters.

    This method can be used in conjunction with the NewScreenReady event to build a list of screen images.

    The returned image can be used in conjunction with the Productivity.OfficeTools CreateWordProcessingDocumentWithGraphicSet method if the installed Office Suite and Office Tools adapter assembly support the use of graphics in word-processing documents.

    Returns the live screen as an image.
    Example
    This samples handles the NewScreenReady event and GetLiveScreenImage to create a list of screen images that include only screens on the Kayak program. Then it uses the CreateWordProcessingDocumentWithGraphicSet method to save the images in a Word document.
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Attachmate.Reflection.UserInterface;
    using Attachmate.Reflection.Productivity;
    using Attachmate.Reflection.Emulation.IbmHosts;
    using Attachmate.Reflection.Framework;
    using System.Drawing;
    using System.Drawing.Imaging;
    using System.IO;
    using Word = Microsoft.Office.Interop.Word;
    
    
    namespace ScreenHistory
    {
        class Program
        {
            static private List<Image> _screenImages = new List<Image>();
    
            static public List<Image>  ScreenImages
            {
                get { return _screenImages; }
    
                set { _screenImages = value; }
    
    
            }
    
            static void terminal_BeforeDisconnect(object sender, EventArgs e)
            {
                IIbmTerminal terminal = (IIbmTerminal)sender;
    
                IScreenHistory history = terminal.Productivity.ScreenHistory;
    
                Console.WriteLine(history.Count);
                if (history.Count > 0)
                {
                    IOfficeTools tools = terminal.Productivity.OfficeTools;
    
                    tools.CreateWordProcessingDocumentWithGraphicSet(ScreenImages, null, null);
    
                    string screenLog = Environment.UserName + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".docx";
    
                    Word.Application word = (Word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");
    
                    word.ActiveDocument.SaveAs(Environment.GetEnvironmentVariable("USERPROFILE") + @"\Documents\" + screenLog);
                    word.ActiveDocument.Close();
                    word.Quit();
    
    
                    history.SaveScreenHistoryFile(Environment.GetEnvironmentVariable("USERPROFILE") + @"\Documents\Micro Focus\InfoConnect\myScreens.rshx", true);
                }
            }
    
    
            static void Main(string[] args)
            {
                //Start a visible instance of InfoConnect or get the instance running at the given channel name
                Application app = MyReflection.CreateApplication("myWorkspace", true);
    
                //Create a terminal from the session document file
                string sessionPath = Environment.GetEnvironmentVariable("USERPROFILE") + @"\Documents\Micro Focus\InfoConnect\demoSession.rd3x";
                IIbmTerminal terminal = (IIbmTerminal)app.CreateControl(sessionPath);
    
                //Make the session visible in the workspace
                IFrame frame = (IFrame)app.GetObject("Frame");
                frame.CreateView(terminal);
    
                IScreenHistory history = terminal.Productivity.ScreenHistory;
    
                history.ManualCaptureOnly = true;
    
                history.ClearAllScreens();
    
                history.ScreenHistoryPanelVisible = true;
    
                history.NumberOfScreensToRemember = 25;
    
                history.ClearHistoryOnDisconnect = false;
    
                terminal.Screen.NewScreenReady += Screen_NewScreenReady;
    
                terminal.BeforeDisconnect += terminal_BeforeDisconnect;
    
    
                Console.ReadLine();
            }
    
            static void Screen_NewScreenReady(object sender, EventArgs e)
            {
                IIbmScreen screen = (IIbmScreen) sender;
    
                Console.WriteLine(screen.GetText(1, 25, 30));
    
    
                if (screen.GetText(1, 25, 30).Contains("KAYAK"))
                {
                    
                    IScreenHistory history = screen.Parent.Productivity.ScreenHistory;
                   
                    //Add to the ScreenImages list
                    byte[] screenImage = history.GetLiveScreenImage();
                    MemoryStream memstr = new MemoryStream(screenImage);
                    Image image = Image.FromStream(memstr);
                    ScreenImages.Add(image);
                }
            }
    
    
        }
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    See Also