示例#1
0
        public void Close([Implicit] StepBro.Core.Execution.ICallContext context)
        {
            if (context != null && context.LoggingEnabled)
            {
                context.Logger.Log(this.GetType().Name, "Close");
            }
            var wasOpen = this.IsOpen;

            this.DoClose(context);
            if (this.IsOpen != wasOpen)
            {
                this.IsOpenChanged?.Invoke(this, EventArgs.Empty);
            }
        }
示例#2
0
        public bool Open([Implicit] StepBro.Core.Execution.ICallContext context)
        {
            var wasOpen = this.IsOpen;

            if (wasOpen)
            {
                if (context != null && context.LoggingEnabled)
                {
                    context.Logger.Log(this.GetType().Name, "Open (but already open)");
                }
                // TODO: Report error and let script handle it.
                return(true);
            }
            else
            {
                if (context != null && context.LoggingEnabled)
                {
                    context.Logger.Log(this.GetType().Name, "Open");
                }
                try
                {
                    var result = this.DoOpen(context);

                    if (this.IsOpen != wasOpen)
                    {
                        this.IsOpenChanged?.Invoke(this, EventArgs.Empty);
                    }
                    return(result);
                }
                catch (Exception ex)
                {
                    if (context != null)
                    {
                        context.ReportError($"Could not open stream; {ex.Message}", exception: ex);
                    }
                    return(false);
                }
            }
        }
示例#3
0
        public static Process Start(
            [Implicit] StepBro.Core.Execution.ICallContext context,
            string filename,
            string arguments      = "",
            TimeSpan startTimeout = new TimeSpan(),
            TimeSpan exitTimeout  = new TimeSpan()
            // bool moveWindow = false
            )
        {
            var process = ObjectMonitorManager.Register(
                new Process((ILogger)context, System.Diagnostics.Process.Start(filename, arguments)));

            if (startTimeout > TimeSpan.Zero)
            {
                if (!process.AwaitStart(context.Logger, startTimeout))
                {
                    //context.RegisterResult()
                    return(process);
                }
            }

            return(process);
        }
示例#4
0
 public abstract string ReadLine([Implicit] StepBro.Core.Execution.ICallContext context, TimeSpan timeout);
示例#5
0
 public abstract void Write([Implicit] StepBro.Core.Execution.ICallContext context, string text);
示例#6
0
 protected abstract void DoClose(StepBro.Core.Execution.ICallContext context);
示例#7
0
 protected abstract bool DoOpen(StepBro.Core.Execution.ICallContext context);
示例#8
0
 private string DoSendAfterDelay([Implicit] StepBro.Core.Execution.ICallContext context, string item, TimeSpan delay, string password, int identifier)
 {
     return("We sent the \"" + item + "\" after a delay. Keyword: \"" + password + "\". ID: " + identifier.ToString());
 }