public void Play_Signon(EhllapiSettings Settings)
        {
            try
            {
                using (DisplaySession sess = new DisplaySession())
                {
                    sess.Connect(Settings.SessId);

                    sess.SendKeys(Settings.UserName);
                    if (Settings.UserName.Length < 10)
                    {
                        sess.SendKeys(Ehllapier.Key.FieldExit);
                    }

                    sess.SendKeys(Settings.Password);
                    if (Settings.Password.Length < 10)
                    {
                        sess.SendKeys(Ehllapier.Key.FieldExit);
                    }

                    sess.SendKeys(Ehllapier.Key.Enter);
                    sess.Wait();

                    // display messages screen breaks on screen. Press enter.
                    if (DisplayMessagesScreen.IsScreen(sess))
                    {
                        sess.SendKeys(Ehllapier.Key.Enter);
                        sess.Wait();
                    }

                    // display program messages screen is displayed. Screen displays on
                    // signon to say "message queue allocated to another job".
                    // Press enter.
                    if (DisplayProgramMessagesScreen.IsScreen(sess))
                    {
                        sess.SendKeys(Ehllapier.Key.Enter);
                        sess.Wait();
                    }

                    // handle the "attempt to recover interactive job" display by running the signoff
                    // option and signing on again.
                    if (RecoverInteractiveJobScreen.IsScreen(sess))
                    {
                        sess.SendKeys("90" + Ehllapier.Key.Enter);
                        sess.Wait();
                        Play_Signon(Settings);
                    }
                }
            }
            catch (ApplicationException excp)
            {
                throw new EhllapiExcp("Play_Signon script failed", excp);
            }
        }
 /// <summary>
 /// send keystrokes intended to signoff the display session to the Settings.SessId
 /// identified display session window.
 /// </summary>
 /// <param name="InSettings"></param>
 public void Play_Signoff(EhllapiSettings InSettings)
 {
     try
     {
         using (DisplaySession sess = new DisplaySession())
         {
             sess.Connect(InSettings.SessId);
             Play_Signoff(sess);
         }
     }
     catch (ApplicationException excp)
     {
         throw new EhllapiExcp("Play_Signoff script failed", excp);
     }
 }
        public static PresentationSpace ReadPresentationSpace(
            EhllapiSettings InSettings)
        {
            PresentationSpace ps = null;

            try
            {
                using (DisplaySession sess = new DisplaySession())
                {
                    sess.Connect(InSettings.SessId);

                    ps = sess.GetPresentationSpace();
                }
            }
            catch (ApplicationException excp)
            {
                throw new EhllapiExcp("ReadPresentationSpace failed", excp);
            }
            return(ps);
        }
        public void AssureSignoff(EhllapiSettings Settings)
        {
            SessionScript script = new SessionScript();

            try
            {
                using (DisplaySession sess = new DisplaySession())
                {
                    sess.Connect(Settings.SessId);
                    var sos = new CommonScreens.SignonScreen(sess.GetPresentationSpace( ));
                    if (sos.IsScreen( ) == true)
                    {
                        Play_Signoff(sess);
                    }
                }
            }
            catch (ApplicationException excp)
            {
                throw new EhllapiExcp("AssureSignoff failed. " + excp.Message, excp);
            }
        }
        public static void Play_ItemLocatorInquiry(EhllapiSettings InSettings)
        {
            try
            {
                PresentationSpace ps     = null;
                SessionScript     script = new SessionScript();

                script.AssureSignoff(InSettings);

                // signon the display
                script.Play_Signon(InSettings);

                using (DisplaySession sess = new DisplaySession())
                {
                    sess.Connect(InSettings.SessId);

                    // tab to the menu option input field
                    sess.SendKeys(Ehllapier.Key.TabRight);

                    // option i
                    sess.SendKeys("i");
                    sess.Wait();

                    // 6174054
                    sess.SendKeys("6174054" + Ehllapier.Key.Enter);
                    sess.Wait();

                    // option 10
                    sess.SendKeys(Ehllapier.Key.TabRight + Ehllapier.Key.NewLine + "10" + Ehllapier.Key.Enter);
                    sess.Wait();
                }
            }
            catch (ApplicationException excp)
            {
                throw new EhllapiExcp("Play_ItemLocatorInquiry script failed", excp);
            }
        }
        public static void Launch_ClientAccessSession(
            EhllapiSettings InSettings, string ProfilePath, string SessId,
            LaunchOptions InLaunchOptions)
        {
            int sessCx = 0;

            if (InLaunchOptions == LaunchOptions.WaitForReady)
            {
                sessCx = pcsapi.QueryActiveSessionCount();
            }

            System.Diagnostics.Process proc = new System.Diagnostics.Process();
            proc.StartInfo.FileName = InSettings.Path_pcsws;

            // enclose the wrkstn profile path in quotes ( in case spaces in the path )
            string profilePath = ProfilePath;

            if (profilePath.IndexOf('"') == -1)
            {
                profilePath = '"' + profilePath + '"';
            }
            proc.StartInfo.Arguments = profilePath;

            //      proc.StartInfo.Arguments =
            //        '"' +@"c:\Program Files\IBM\Client Access\Emulator\private\pc04a.ws" + '"';
            //      proc.StartInfo.Arguments = "'" + InWrkstnProfilePath + "'";
            //      proc.StartInfo.Arguments = @"..\private\pc04a.ws";
            if (SessId.IsNullOrEmpty() == false)
            {
                proc.StartInfo.Arguments = @"/S=" + SessId + " " + proc.StartInfo.Arguments;
            }

            proc.Start();

            proc.WaitForInputIdle(5000);

            // wait until session count increments. that tells us the new session
            // is completely started.
            if (InLaunchOptions == LaunchOptions.WaitForReady)
            {
                int newSessCx = 0;
                while (newSessCx <= sessCx)
                {
                    Thread.Sleep(100);
                    newSessCx = pcsapi.QueryActiveSessionCount();
                }

                // wait until the SessId identified session can be connected to.
                bool isConnected = false;
                int  cummWait    = 0;
                while (isConnected == false)
                {
                    using (DisplaySession sess = new DisplaySession())
                    {
                        try
                        {
                            isConnected = true;
                            sess.Connect(SessId);
                            sess.Wait();
                        }
                        catch (EhllapiExcp)
                        {
                            cummWait += 300;
                            if (cummWait > 10000)
                            {
                                throw new ApplicationException("client access session connection timeout");
                            }
                            isConnected = false;
                            Thread.Sleep(300);
                        }
                    }
                }

                // wait for SystemAvailable.
                int tx = 0;
                while (true)
                {
                    ++tx;
                    if (tx > 1000)
                    {
                        throw new EhllapiExcp("Wait for system available timeout");
                    }
                    using (DisplaySession sess = new DisplaySession())
                    {
                        sess.Connect(SessId);
                        if (sess.SystemAvailable == true)
                        {
                            break;
                        }
                        Thread.Sleep(100);
                    }
                }
            }
        }