Reflection .NET API
Attachmate.Reflection Assembly / Attachmate.Reflection.Productivity Namespace / IScreenHistory Interface / Count Property
Example


In This Topic
    Count Property (IScreenHistory)
    In This Topic
    Returns the number of screens listed in the Screen History of the session.
    Syntax
    'Declaration
     
    
    ReadOnly Property Count As Integer
    'Usage
     
    
    Dim instance As IScreenHistory
    Dim value As Integer
     
    value = instance.Count
    int Count {get;}
    Example
    This sample uses the Count property to check for an empty list.
    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\Reflection\myScreens.rshx", true);
                }
            }
    
    
            static void Main(string[] args)
            {
                //Start a visible instance of Reflection 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\Reflection\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