示例#1
0
        public void LoadOneScriptfileBehind()
        {
            var mainViewModel = new MainViewModel();

            Assert.AreEqual(0, mainViewModel.DocumentItems.Count);

            var file = StepBroMain.LoadScriptFile(new object(), @"C:\SW_development\Private\StepBro\examples\scripts\Demo Procedure.sbs");

            Assert.AreEqual(1, mainViewModel.DocumentItems.Count);
            Assert.IsFalse(mainViewModel.DocumentItems[0].IsOpen);
        }
示例#2
0
        public void LoadOneScriptfileDeleteDocItem()
        {
            var mainViewModel = new MainViewModel();

            Assert.AreEqual(0, mainViewModel.DocumentItems.Count);

            var file = mainViewModel.LoadScriptFile(@"C:\SW_development\Private\StepBro\examples\scripts\Demo Procedure.sbs");

            Assert.AreEqual(1, mainViewModel.DocumentItems.Count);

            mainViewModel.DocumentItems.RemoveAt(0);    // What happens when user closes the document view.
            Assert.AreEqual(0, mainViewModel.DocumentItems.Count);
            Assert.AreEqual(0, StepBroMain.GetLoadedFilesManager().ListFiles <ILoadedFile>().ToList().Count());
        }
示例#3
0
 public void Cleanup()
 {
     StepBroMain.DeinitializeInternal(true);
 }
示例#4
0
        private static int Main(string[] args)
        {
            object consoleResourceUserObject = new object();
            int    retval = 0;

            Console.WriteLine("StepBro console application. Type 'stepbro --help' to show the help text.");

            m_commandLineOptions = StepBro.Core.General.CommandLineParser.Parse <CommandLineOptions>(null, args);

            if (m_commandLineOptions.HasParsingErrors)
            {
                return(-1);
            }

            try
            {
                StepBroMain.Initialize();

                if (m_commandLineOptions.Verbose)
                {
                    var logSinkManager = StepBro.Core.Main.GetService <ILogSinkManager>();
                    logSinkManager.Add(new ConsoleLogSink());
                }

                if (!String.IsNullOrEmpty(m_commandLineOptions.InputFile))
                {
                    if (m_commandLineOptions.Verbose)
                    {
                        Console.WriteLine("Filename: {0}", m_commandLineOptions.InputFile);
                    }
                    IScriptFile file = null;
                    try
                    {
                        file = StepBroMain.LoadScriptFile(consoleResourceUserObject, m_commandLineOptions.InputFile);
                        if (file == null)
                        {
                            retval = -1;
                            Console.WriteLine("Error: Loading script file failed ( " + m_commandLineOptions.InputFile + " )");
                        }
                    }
                    catch (Exception ex)
                    {
                        retval = -1;
                        Console.WriteLine("Error: Loading script file failed: " + ex.GetType().Name + ", " + ex.Message);
                    }

                    if (file != null)
                    {
                        var parsingSuccess = StepBroMain.ParseFiles(true);
                        if (parsingSuccess)
                        {
                            if (!String.IsNullOrEmpty(m_commandLineOptions.TargetElement))
                            {
                                IFileElement element = StepBroMain.TryFindFileElement(m_commandLineOptions.TargetElement);
                                if (element != null && element is IFileProcedure)
                                {
                                    var      procedure = element as IFileProcedure;
                                    object[] arguments = m_commandLineOptions?.Arguments.Select(
                                        (a) => StepBroMain.ParseExpression(procedure?.ParentFile, a)).ToArray();
                                    try
                                    {
                                        object result = StepBroMain.ExecuteProcedure(procedure, arguments);
                                        if (result != null)
                                        {
                                            Console.WriteLine("Procedure execution ended. Result: " + result.ToString());
                                        }
                                        else
                                        {
                                            Console.WriteLine("Procedure execution ended.");
                                        }
                                    }
                                    catch (TargetParameterCountException)
                                    {
                                        retval = -1;
                                        Console.WriteLine("Error: The number of arguments does not match the target procedure.");
                                    }
                                }
                                else if (element != null && element is ITestList)
                                {
                                    throw new NotImplementedException("Handling of test list tarteg not implemented.");
                                }
                                else
                                {
                                    retval = -1;
                                    if (element == null)
                                    {
                                        Console.WriteLine($"Error: File element named '{m_commandLineOptions.TargetElement} was not found.");
                                    }
                                    else
                                    {
                                        Console.WriteLine($"Error: File element type for '{m_commandLineOptions.TargetElement} cannot be used as an execution target.");
                                    }
                                }
                            }
                        }
                        else
                        {
                            Console.WriteLine("Parsing errors!");
                            foreach (var err in file.Errors.GetList())
                            {
                                if (!err.JustWarning)
                                {
                                    Console.WriteLine($"    Line {err.Line}: {err.Message}");
                                }
                            }
                            retval = -1;
                        }
                    }
                }
                else
                {
                    // If no file should be opened, what then?
                    retval = -1;
                    Console.WriteLine("Error: File could not be opened.");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error: {ex.GetType().Name}, {ex.Message}");
                retval = -1;
            }
            finally
            {
                StepBroMain.Deinitialize();
            }

            if (m_commandLineOptions.AwaitKeypress)
            {
                Console.WriteLine("<press any key to continue>");
                while (!Console.KeyAvailable)
                {
                    System.Threading.Thread.Sleep(25);
                }
                Console.ReadKey();
            }
            return(retval);
        }