Пример #1
0
        public void EINS_Submits()
        {
            BTask task = new BTask("einstein_all_sections", "localagency");

            task.TaskSteps.Add(new TaskStep("ClickByContent", new string[] { "li.rtsLI", ".*EINST.*", "true" }));
            task.TaskSteps.Add(new TaskStep("Click", new string[] { "_Launch" }));
            for (int i = 0; i < 7; i++)
            {
                task.TaskSteps.Add(new TaskStep("SetOption", new string[] { "ddl_Sections", $"{i}" }));
                task.TaskSteps.Add(new TaskStep("Click", new string[] { "_btnEdit" }));
                task.TaskSteps.Add(new TaskStep("Click", new string[] { "_DeleteButton" }));
                task.TaskSteps.Add(new TaskStep("AcceptAlert", new string[] { "1000" }));
                task.TaskSteps.Add(new TaskStep("Click", new string[] { "AddNewRecordButton" }));
                task.TaskSteps.Add(new TaskStep("RadFormFill", new string[] { "*[class*='EinsteinGrid']" }));
                task.TaskSteps.Add(new TaskStep("Click", new string[] { "a[id*='_PerformInsertButton']" }));
                task.TaskSteps.Add(new TaskStep("Click", new string[] { "*[id*='_rbtnDownload']" }));
                task.TaskSteps.Add(new TaskStep("Pause", new string[] { "1000" }));
                task.TaskSteps.Add(new TaskStep("Key", new string[] { "_fileUpload", eins[i] }));
                task.TaskSteps.Add(new TaskStep("Click", new string[] { "_cmdUpload, _btnSave" }));
                tasks.Add(task);
            }
            CommandProcessor processor = new CommandProcessor(Session.Context(task.Context), new Mock <ILogger <ContextProvider> >().Object);

            processor.Process(task);
            Utils.WriteTasks(tasks);
        }
Пример #2
0
        /// <summary>
        /// 初始化数据库信息
        /// </summary>
        /// <returns>结果</returns>
        public Result InitDatabaseInfo()
        {
            Result result = new Result();

            try
            {
                var conInfo = new BConString().GetConString(this.TaskInfo.BusinessKeyID);
                if (string.IsNullOrWhiteSpace(conInfo?.KeyID))
                {
                    result.Msg = "获取当前任务信息失败";
                    return(result);
                }

                IDBOperator op = new DBOperator();
                ////获取数据库连接
                SqlSugarClient client = null;
                ///根据链接获取此链接下所有数据库
                var dataBases = op.GetAllDataBase(conInfo.ConnectionString, ref client);
                ///根据数据库获取所有表
                if (dataBases == null || dataBases.Count == 0)
                {
                    result.Msg     = "当前链接没有数据库";
                    result.Success = true;
                    return(result);
                }

                Dictionary <string, List <Table> > dBAndTables = new Dictionary <string, List <Table> >();
                ////这里表多了会不会超时,待处理
                foreach (var item in dataBases)
                {
                    Thread.Sleep(100);
                    dBAndTables.Add(item, op.GetAllTables(item, client));
                }

                ///根据规则判断表的生成规则,并生成tables的表信息
                var tables = this.BuildTableModel(dBAndTables, conInfo);
                var res    = new BTable().AddTableBatch(tables);
                ////筛选需要定期建表的
                var           cycleTables = tables.FindAll(p => p.SplitType != SplitType.None && p.SplitType != SplitType.HASH);
                List <DBTask> tasks       = new List <DBTask>();
                cycleTables.ForEach(p => tasks.Add(new DBTask()
                {
                    BusinessKeyID = p.TabelKeyID, BusinessType = BusinessType.表建表
                }));
                var insertRes = new BTask().AddTasks(tasks);
                if (insertRes.Success)
                {
                    this.TaskInfo.NextExecuteTime = DateTime.Now.AddDays(1);
                }

                return(insertRes);
            }
            catch (Exception e)
            {
                NLog.LogManager.GetCurrentClassLogger().Error($"{e}");
                result.Msg = e.Message;
            }

            return(result);
        }
Пример #3
0
        public BTask GetBTask(SubjectTheme theme, int num)
        {
            string fileName = subject.ToString() + "/" + theme.Num.ToString() + @"/b/" + num.ToString() + "/" + "task.txt";
            var    assets   = MRApplication.GetAssetManager();

            try
            {
                using (StreamReader reader = new  StreamReader(assets.Open(fileName))) {
                    string content = reader.ReadToEnd();

                    var        json     = JsonObject.Parse(content);
                    JsonObject jsonTask = json ["task"] as JsonObject;

                    var bTask = new BTask(num, theme, subject);
                    SetCommonTaskParams(jsonTask, bTask);


                    List <AVariant> variants = new List <AVariant> ();
                    bTask.Variant = jsonTask ["variant"];
                    return(bTask);
                }
            }
            catch (Exception e) {
                return(null);
            }
        }
Пример #4
0
        public void JiraIssue_Resolver()
        {
            var ctx = Session.Context("jira");
            var dvr = ctx.SessionDriver;

            ctx.SessionDriver.Create();

            CommandProcessor processor = new CommandProcessor(ctx, new Mock <ILogger <ContextProvider> >().Object);

            processor.Process(ctx.ContextConfig.conntask);

            var urlProvider = new UrlProvider(selector, matchPattern);

            urlProvider.Execute(ctx);
            BTask task = new BTask("startprog_tickets", "jira");

            foreach (KeyValuePair <string, string> kvp in urlProvider.Items)
            {
                task.TaskSteps.Add(new TaskStep("Url", new string[] { kvp.Key }));
                task.TaskSteps.Add(new TaskStep("Pause", new string[] { "1500" }));
                task.TaskSteps.Add(new TaskStep("Click", new string[] { "a[title*='Resolve']" }));
                task.TaskSteps.Add(new TaskStep("Click", new string[] { "input[id*='issue-workflow-transition-submit']" }));
                task.TaskSteps.Add(new TaskStep("Pause", new string[] { "1500" }));
                task.TaskSteps.Add(new TaskStep("Click", new string[] { "a[title*='Ready To Test']" }));
                task.TaskSteps.Add(new TaskStep("Click", new string[] { "input[id*='issue-workflow-transition-submit']" }));
                task.TaskSteps.Add(new TaskStep("Pause", new string[] { "1500" }));
                tasks.Add(task);
            }
            processor.Process(task);
            //Utils.WriteTask(task);
            //dvr.Dispose();
        }
Пример #5
0
        public void JiraTime_Taker()
        {
            var ctx = Session.Context("jira");
            var dvr = ctx.SessionDriver;

            ctx.SessionDriver.Create();
            CommandProcessor processor = new CommandProcessor(ctx, new Mock <ILogger <ContextProvider> >().Object);

            processor.Process(ctx.ContextConfig.conntask);

            var urlProvider = new UrlProvider(selector, matchPattern);

            urlProvider.Execute(ctx);
            BTask task = new BTask("taketime", "jira");

            foreach (KeyValuePair <string, string> kvp in urlProvider.Items)
            {
                task.TaskSteps.Add(new TaskStep("OpenTab", new string[] { kvp.Key }));
                task.TaskSteps.Add(new TaskStep("SetWait", new string[] { "1" }));
                task.TaskSteps.Add(new TaskStep("Click", new string[] { "opsbar-operations_more" }));
                task.TaskSteps.Add(new TaskStep("Click", new string[] { "log-work" }));
                task.TaskSteps.Add(new TaskStep("Key", new string[] { "input[id='log-work-time-logged']", "15m" }));
                task.TaskSteps.Add(new TaskStep("Click", new string[] { "input[id='log-work-submit']" }));
                task.TaskSteps.Add(new TaskStep("Pause", new string[] { "2500" }));
            }
            task.TaskSteps.Add(new TaskStep("SessionDispose", new string[] { "1" }));
            processor.Process(task);
            Utils.WriteTask(task);
            //dvr.Dispose();
        }
Пример #6
0
        public static void WriteTask(BTask task)
        {
            var serializer = new SerializerBuilder().WithNamingConvention(CamelCaseNamingConvention.Instance).Build();
            var ser        = serializer.Serialize(task);

            ser = Regex.Replace(ser, @"(&o0\r\n\s\s)|(- \*o0\r\n)", "");
            File.WriteAllText($"c:\\bom\\unittest\\{task.Context}_{task.Name}.yaml", ser, Encoding.ASCII);
            File.WriteAllText($"c:\\bom\\unittest\\{task.Context}_{task.Name}.bat", $"bom run -k -t c:\\bom\\unittest\\{task.Context}_{task.Name}.yaml", Encoding.ASCII);
        }
Пример #7
0
        public Object Done(int taskid)
        {
            Payload payload = BAccount.ConfirmToken(this.Request);

            if (payload == null)
            {
                return(new { result = false, info = "Não autorizado." });
            }
            return(BTask.DoneTask(taskid, payload.aud));
        }
Пример #8
0
        protected void AnswerTextBoxChanged(object sender, EventArgs args)
        {
            EditText answerTextBox = (EditText)sender;

            if (tasks [currentTaskToShow] is BTask)
            {
                BTask task = (BTask)tasks [currentTaskToShow];
                task.UserAnswer = answerTextBox.Text;
            }
        }
Пример #9
0
        public void ebil_writes()
        {
            BTask task = new BTask("ebil", "ebil");

            task.TaskSteps.Add(new TaskStep("Url", new string[] { "https://secure.ebillity.com/firm4.0/TimeExpense/WeeklyTimeSheet2.aspx" }));
            task.TaskSteps.Add(new TaskStep("Pause", new string[] { "900" }));
            task.TaskSteps.Add(new TaskStep("Click", new string[] { "btnCopyTimeSheet" }));
            task.TaskSteps.Add(new TaskStep("Pause", new string[] { "900" }));
            //task.TaskSteps.Add(new TaskStep("Script", new string[] { "document.getElementsByClassName('btn_green')[0].click();" }));
            tasks.Add(task);
            Utils.WriteTasks(tasks);
        }
Пример #10
0
        public void Process(BTask task)
        {
            foreach (var taskstep in task.TaskSteps)
            {
                if (taskstep.Cmd.ToLower() == "setwait")
                {
                    ctx.SessionDriver.SetWait(Convert.ToDouble(taskstep.Args[0] ?? "1")); continue;
                }

                var typ = Assm.GetTypes().Where(t => t.Name.Contains(taskstep.Cmd) && typeof(ICommand)
                                                .IsAssignableFrom(t)).FirstOrDefault();

                Type            tCmd    = Type.GetType($"{typ.FullName}, {typ.Namespace}") ?? Type.GetType($"{typ.FullName}, BOM");
                ParameterInfo[] PI      = tCmd.GetConstructors()[0].GetParameters();
                List <object>   oparms  = new List <object>();
                int             parmcnt = 0;
                foreach (ParameterInfo parm in PI)
                {
                    string value = (taskstep.Args.Count() >= parmcnt) ? taskstep.Args[parmcnt] : null;
                    parmcnt++;
                    if (parm.ParameterType.Name.ToLower().Contains("int"))
                    {
                        oparms.Add(Convert.ToInt32(value ?? "0"));
                    }
                    else if (parm.ParameterType.Name.ToLower().Contains("bool"))
                    {
                        oparms.Add(Convert.ToBoolean(value ?? "false"));
                    }
                    else if (parm.ParameterType.Name.ToLower().Contains("double"))
                    {
                        oparms.Add(Convert.ToDouble(value ?? "0"));
                    }
                    else
                    {
                        oparms.Add(value);
                    }
                }
                try
                {
                    ICommand obj = (ICommand)Activator.CreateInstance(tCmd, oparms.ToArray());
                    obj.Execute(ctx);
                }
                catch (Exception ex)
                {
                    logger.LogWarning("ICommand:CreateInstance {c}\n", tCmd);
                    logger.LogWarning("oparms: {o}", JsonConvert.SerializeObject(oparms));
                    logger.LogError("\n{o}", ex.Message);
                }
            }
        }
Пример #11
0
        public Object Delete(int taskid)
        {
            Payload payload = BAccount.ConfirmToken(this.Request);

            if (payload == null || (!payload.rol.Contains(3) && !payload.rol.Contains(6)))
            {
                return(new { result = false, info = "Não autorizado." });
            }
            if (!BTask.DeleteTask(taskid))
            {
                return(new { result = false, info = "Não foi possível eliminar a tarefa" });
            }
            return(new { result = true });
        }
Пример #12
0
        public Object Put([FromBody] TblTasks task)
        {
            Payload payload = BAccount.ConfirmToken(this.Request);

            if (payload == null || (!payload.rol.Contains(3) && !payload.rol.Contains(6)))
            {
                return(new { result = false, info = "Não autorizado." });
            }
            if (!BTask.EditTask(task, payload.aud))
            {
                return(new { result = false, info = "Não foi possível alterar a tarefa" });
            }
            return(new { result = true });
        }
Пример #13
0
 public void AddDBTaskTest()
 {
     try
     {
         var task = new DBTask()
         {
             BusinessKeyID = "202102071129559905157225",
             BusinessType  = BusinessType.表建表,
         };
         var res = new BTask().AddDBTask(task);
     }
     catch (Exception)
     {
     }
 }
Пример #14
0
        public Object GetRealizations(int taskid)
        {
            Payload payload = BAccount.ConfirmToken(this.Request);

            if (payload == null || (!payload.rol.Contains(3) && !payload.rol.Contains(6)))
            {
                return(new { result = false, info = "Não autorizado." });
            }
            var tasks = BTask.GetRealizations(taskid);

            if (tasks == null)
            {
                return(new { result = false, info = "Não tem tarefas realizadas." });
            }
            return(new { result = true, data = tasks });
        }
Пример #15
0
        public Object GetSentNotifs()
        {
            Payload payload = BAccount.ConfirmToken(this.Request);

            if (payload == null)
            {
                return(new { result = false, info = "Não autorizado." });
            }
            var tasks = BTask.GetMyTasks(payload.aud);

            if (tasks == null)
            {
                return(new { result = false, info = "Não tem tarefas." });
            }
            return(new { result = true, data = tasks });
        }
Пример #16
0
        public void CL_Subs()
        {
            BTask task = new BTask("subl_search", "bom");

            task.TaskSteps.Add(new TaskStep("Url", new string[] { "https://dayman.cyber-balance.com/jira/browse/CS-8450" }));
            task.TaskSteps.Add(new TaskStep("Click", new string[] { "opsbar-operations_more" }));
            task.TaskSteps.Add(new TaskStep("Click", new string[] { "log-work" }));
            task.TaskSteps.Add(new TaskStep("Key", new string[] { "input[id='log-work-time-logged']", "15m" }));
            task.TaskSteps.Add(new TaskStep("Click", new string[] { "input[id='log-work-submit']" }));
            task.TaskSteps.Add(new TaskStep("Pause", new string[] { "900" }));
            tasks.Add(task);

            //CommandProcessor processor = new CommandProcessor(Session.Context(task.Context), new Mock<ILogger<ContextProvider>>().Object);
            //processor.Process(task);

            Utils.WriteTasks(tasks);
        }
Пример #17
0
        public void User_Updates()
        {
            BTask task = new BTask("USER", "dayadmin");

            task.TaskSteps.Add(new TaskStep("OpenTab", new string[] { "~/UserAccessNew/SelectUser.aspx" }));
            task.TaskSteps.Add(new TaskStep("Key", new string[] { "_WebTextEdit1", "ll-d-rob" }));
            task.TaskSteps.Add(new TaskStep("Click", new string[] { "_btn_Run" }));
            task.TaskSteps.Add(new TaskStep("Click", new string[] { "_link_UserID" }));
            task.TaskSteps.Add(new TaskStep("SwitchTo", new string[] { "-1" }));
            task.TaskSteps.Add(new TaskStep("Click", new string[] { "input[id='ctl00_ctl00_contentPh_RightBody_ContentPlaceHolder1_fv_Profile_btn_Edit']" }));
            tasks.Add(task);

            CommandProcessor processor = new CommandProcessor(Session.Context(task.Context), new Mock <ILogger <ContextProvider> >().Object);

            processor.Process(task);

            Utils.WriteTasks(tasks);
        }
Пример #18
0
        public void JiraIssue_Scraper()
        {
            var ctx = Session.Context("jira");
            var dvr = ctx.SessionDriver; //|.*Prepopulation.*  .*BOD.*Section.*[1-3].*|.*CSHELP-2899

            ctx.SessionDriver.Create( );
            BTask task = new BTask("scrape_issue", "jira");

            task.TaskSteps.Add(new TaskStep("Url", new string[] { "https://dayman.cyber-balance.com/jira/si/jira.issueviews:issue-html/CS-8621/CS-8621.html" }));
            task.TaskSteps.Add(new TaskStep("ClickByContent", new string[] { "Validate and Approve" }));
            task.TaskSteps.Add(new TaskStep("Click", new string[] { "header-operations" }));
            task.TaskSteps.Add(new TaskStep("Click", new string[] { "allCsvFields" }));
            task.TaskSteps.Add(new TaskStep("Click", new string[] { "csv-export-dialog-export-button" }));
            tasks.Add(task);
            CommandProcessor processor = new CommandProcessor(Session.Context(task.Context), new Mock <ILogger <ContextProvider> >().Object);

            processor.Process(task);
            //Utils.WriteTasks(tasks);
            //dvr.Dispose();
        }
Пример #19
0
        public void Assmt_All()
        {
            BTask task = new BTask("assmt_all_tabs", "localagency");

            task.TaskSteps.Add(new TaskStep("ClickByContent", new string[] { "li.rtsLI", ".*BOD 18-02 Rem.*", "true" }));
            task.TaskSteps.Add(new TaskStep("Click", new string[] { "_lnkAddAssm" }));
            task.TaskSteps.Add(new TaskStep("Click", new string[] { "*[id*='AssmtGrid_ctl00_ctl04' ] .rgExpandIcon" }));
            task.TaskSteps.Add(new TaskStep("OpenTab", new string[] { "~/ReporterHome.aspx" }));
            task.TaskSteps.Add(new TaskStep("OpenTab", new string[] { "~/ReporterHome.aspx" }));
            task.TaskSteps.Add(new TaskStep("Click", new string[] { "_Launch" }));
            task.TaskSteps.Add(new TaskStep("SetOption", new string[] { "ddl_Sections", "0" }));
            task.TaskSteps.Add(new TaskStep("OpenTab", new string[] { "" }));
            task.TaskSteps.Add(new TaskStep("SetOption", new string[] { "ddl_Sections", "1" }));
            task.TaskSteps.Add(new TaskStep("OpenTab", new string[] { "" }));
            task.TaskSteps.Add(new TaskStep("SetOption", new string[] { "ddl_Sections", "2" }));
            task.TaskSteps.Add(new TaskStep("SwitchTo", new string[] { "0" }));
            tasks.Add(task);

            CommandProcessor processor = new CommandProcessor(Session.Context(task.Context), new Mock <ILogger <ContextProvider> >().Object);

            processor.Process(task);

            Utils.WriteTasks(tasks);
        }
Пример #20
0
        static void Main(string[] args)
        {
            ServiceProvider serviceProvider = RegisterServices(args);
            IConfiguration  configuration   = serviceProvider.GetService <IConfiguration>();
            ILogger         logger          = serviceProvider.GetService <ILogger <Program> >();
            ISessionContext ctx;

            BTask task = new BTask();

            var exit = Parser.Default.ParseArguments <RunOptions, ConfigOptions>(args)
                       .MapResult(
                (RunOptions o) =>
            {
                logger.LogInformation("RunOptions: {o}", JsonConvert.SerializeObject(o));
                if (o.Task != null)
                {
                    task = serviceProvider.GetService <ISettingProvider <BTask> >().Get(o.Task);
                }
                ctx = serviceProvider.GetService <ISettingProvider <SessionContext> >().Get(o.Context ?? task.Context);

                task.TaskSteps.InsertRange(0, ctx.ContextConfig.conntask.TaskSteps);

                ctx.SessionDriver.ChromeOptions.AddArgument("log-level=3");
                if (o.Headless)
                {
                    ctx.SessionDriver.ChromeOptions.AddArgument("headless");
                }
                ctx.SessionDriver.Create();

                CommandProcessor processor = new CommandProcessor(ctx, logger);
                processor.Process(task);

                if (!o.KeepAlive)
                {
                    ctx.SessionDriver.Dispose();
                }
                return(0);
            },
                (ConfigOptions o) => {
                StringBuilder sb = new StringBuilder();

                sb.AppendFormat("\n\n{0}vars{0}", new string('-', 9));
                sb.AppendFormat("\n{0}", JsonConvert.SerializeObject(o));
                sb.AppendFormat("\nEnVar: {0}", Environment.GetEnvironmentVariable("bom", EnvironmentVariableTarget.User));
                sb.AppendFormat("\nAssmLoc: {0}", Assembly.GetExecutingAssembly().Location);

                var paths = configuration.GetSection("paths");
                if (paths == null)
                {
                    logger.LogWarning(" TaskProvider config.GetSection null: {o}", paths);
                }

                var yamltasks = configuration.GetSection("paths:yamltasks");
                if (yamltasks == null)
                {
                    logger.LogWarning(" TaskProvider config.GetSection null: {o}", yamltasks);
                }
                else
                {
                    sb.AppendFormat("\npaths:yamltasks : {0}", yamltasks.Value);
                }


                var ConfigContexts = configuration.GetSection("contexts").Get <List <BomConfigContext> >();
                sb.AppendFormat("\n{0}contexts{0}", new string('-', 9));
                if (ConfigContexts == null)
                {
                    logger.LogWarning("{o}", ConfigContexts);
                }
                else
                {
                    foreach (var context in ConfigContexts)
                    {
                        sb.AppendFormat("\n{0}context: {1}{0}", new string('-', 9), context.name);
                        sb.AppendFormat("\nroot: {0}", context.root);
                        sb.AppendFormat("\n{0}", JsonConvert.SerializeObject(context.conntask));
                    }
                }

                logger.LogInformation("{0}", sb.ToString());
                return(0);
            },
                errs => 1);

            serviceProvider.Dispose();
        }
Пример #21
0
 public TaskProcessor(BTask task, ILogger Logger)
 {
     this.task   = task;
     this.logger = Logger;
 }