コード例 #1
0
        protected override void Execute(CodeActivityContext context)
        {
            int    field   = Field.Get(context);
            string text    = Text.Get(context);
            var    timeout = Timeout.Get(context);

            if (Timeout == null || Timeout.Expression == null)
            {
                timeout = TimeSpan.FromSeconds(3);
            }
            var vars = context.DataContext.GetProperties();

            Interfaces.VT.ITerminalSession session = null;
            foreach (dynamic v in vars)
            {
                var val = v.GetValue(context.DataContext);
                if (val is Interfaces.VT.ITerminalSession _session)
                {
                    session = val;
                }
            }
            if (session == null)
            {
                throw new ArgumentException("Failed locating terminal session");
            }
            if (session.Terminal == null)
            {
                throw new ArgumentException("Terminal Sessoin not initialized");
            }
            if (!session.Terminal.IsConnected)
            {
                throw new ArgumentException("Terminal Sessoin not connected");
            }
            Interfaces.VT.IField _f = null;
            var sw = new Stopwatch();

            sw.Start();

            do
            {
                _f = session.Terminal.GetField(field);
                if (sw.Elapsed > timeout)
                {
                    throw new Exception("Failed locating field #" + field);
                }
            } while (_f == null || (_f.Location.Column == 0 && _f.Location.Row == 0));
            if (_f == null)
            {
                throw new ArgumentException("Field not found");
            }
            session.Refresh();
            if (WaitForKeyboard.Get(context))
            {
                session.Terminal.WaitForKeyboardUnlocked(timeout);
            }
            session.Terminal.SendText(field, text);
            if (WaitForKeyboard.Get(context))
            {
                session.Terminal.WaitForKeyboardUnlocked(timeout);
            }
        }