Exemple #1
0
        /// <summary>
        /// 一键运行
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnRunAll_Click(object sender, RoutedEventArgs e)
        {
            Compile cp = new Compile();

            Task.Run(
                () =>
            {
                int i = -1;
                foreach (CaseScript Script in mv.CaseScripts)
                {
                    i++;
                    string result               = "";//案例执行结果 成功/失败
                    string info                 = CSVFileHelper.OpenScript(Script.FullPath).ToString();
                    string[] textArry           = info.Split('\n');
                    PrintHelper.Print.PrintData = this.PrintData;
                    PrintHelper.Print.AppendLine($"\r\n**********开始执行案例:{Script.CaseName}**********");
                    cp.Run(textArry, ref result);

                    DataGridRow row = (DataGridRow)this.dgCase.ItemContainerGenerator.ContainerFromIndex(i);
                    if (result != "")
                    {
                        this.Dispatcher.Invoke(() => { row.Foreground = new SolidColorBrush(Colors.Red); });
                        MessageBox.Show($"案例{Script.CaseName}执行失败,error:{result}", "异常");
                        continue;
                    }
                    else
                    {
                        this.Dispatcher.Invoke(() => { row.Foreground = new SolidColorBrush(Colors.Green); });
                    }
                }
                PrintHelper.Print.AppendLine($"\r\n所有案例脚本执行完毕!!!!!!!!!!!!");
            }
                );
        }
        /// <summary>
        /// 加载并显示脚本信息
        /// </summary>
        private string LoadScript(string path)
        {
            string info = "";

            if (File.Exists(path))
            {
                SrciptDoc.FileName = path;
                info           = CSVFileHelper.OpenScript(path).ToString();
                SrciptDoc.Text = info;
            }
            return(info);
        }