Esempio n. 1
0
        public System.Action GenerateAction(int taskID, ActionModel action)
        {
            return(() =>
            {
                OnEventStateChanged?.Invoke(taskID, action.ID, ActionInvokeStateType.Runing);
                var p = ObjectConvert.Get <LoopsActionParamsModel>(action.Parameter);
                int i = 0;
                if (p.Count <= 0)
                {
                    p.Count = 1;
                }
                var result = new ActionResultModel();
                result.ID = action.ID;
                result.Result = new Dictionary <int, object>();
                result.Result.Add((int)LoopsResultType.Index, "1");
                ActionTaskResulter.Add(taskID, result);
                while (true)
                {
                    result.Result[(int)LoopsResultType.Index] = i.ToString();
                    ActionTask.Invoke(taskID, p.Actions, taskID == ActionTask.TestTaskID, true);
                    i++;

                    if (i == p.Count)
                    {
                        break;
                    }
                }

                OnEventStateChanged?.Invoke(taskID, action.ID, ActionInvokeStateType.Done);
            });
        }
Esempio n. 2
0
 public System.Action GenerateAction(int taskID, ActionModel action)
 {
     return(() =>
     {
         var p = ObjectConvert.Get <OpenURLActionParamsModel>(action.Parameter);
         var result = new ActionResultModel();
         result.ID = action.ID;
         result.Result = new Dictionary <int, string>();
         result.Result.Add((int)CommonResultKeyType.IsSuccess, "false");
         p.URL = ActionParameterConverter.ConvertToString(taskID, p.URL);
         try
         {
             ProcessStartInfo psi = new ProcessStartInfo
             {
                 FileName = p.URL,
                 UseShellExecute = true
             };
             Process.Start(psi);
             result.Result[(int)CommonResultKeyType.IsSuccess] = "true";
         }
         catch (Exception e)
         {
             LogHelper.Error(e.ToString());
         }
         //返回数据
         ActionTaskResulter.Add(taskID, result);
     });
 }
Esempio n. 3
0
        public System.Action GenerateAction(int taskID, ActionModel action)
        {
            return(() =>
            {
                OnEventStateChanged?.Invoke(taskID, action.ID, ActionInvokeStateType.Runing);
                var p = ObjectConvert.Get <ReadFileActionParamsModel>(action.Parameter);
                var result = new ActionResultModel();
                result.ID = action.ID;
                result.Result = new Dictionary <int, object>();
                result.Result.Add((int)ReadFileResultType.IsSuccess, false);
                result.Result.Add((int)ReadFileResultType.Content, string.Empty);

                p.FilePath = ActionParameterConverter.ConvertToString(taskID, p.FilePath);
                Debug.WriteLine("read file:" + p.FilePath);
                try
                {
                    result.Result[(int)ReadFileResultType.Content] = File.ReadAllText(p.FilePath);
                    result.Result[(int)ReadFileResultType.IsSuccess] = true;
                }
                catch (Exception e)
                {
                    LogHelper.Error(e.ToString());
                }
                //返回数据
                ActionTaskResulter.Add(taskID, result);
                OnEventStateChanged?.Invoke(taskID, action.ID, ActionInvokeStateType.Done);
            });
        }
Esempio n. 4
0
        public System.Action GenerateAction(int taskID, ActionModel action)
        {
            return(() =>
            {
                var p = ObjectConvert.Get <WriteFileActionParameterModel>(action.Parameter);
                var result = new ActionResultModel();
                result.ID = action.ID;
                result.Result = new Dictionary <int, string>();
                result.Result.Add((int)CommonResultKeyType.IsSuccess, "false");
                p.FilePath = ActionParameterConverter.ConvertToString(taskID, p.FilePath);
                p.Content = ActionParameterConverter.ConvertToString(taskID, p.Content);

                Debug.WriteLine("write file:" + p.FilePath);
                try
                {
                    File.WriteAllText(p.FilePath, p.Content);
                    result.Result[(int)CommonResultKeyType.IsSuccess] = "true";
                }
                catch (Exception e)
                {
                    LogHelper.Error(e.ToString());
                }
                //返回数据
                ActionTaskResulter.Add(taskID, result);
            });
        }
Esempio n. 5
0
        public System.Action GenerateAction(int taskID, ActionModel action)
        {
            return(() =>
            {
                OnEventStateChanged?.Invoke(taskID, action.ID, ActionInvokeStateType.Runing);
                var p = ObjectConvert.Get <JsonDeserializeActionParamsModel>(action.Parameter);
                var result = new ActionResultModel();
                result.ID = action.ID;
                result.Result = new Dictionary <int, object>();
                result.Result.Add((int)CommonResultKeyType.IsSuccess, false.ToString());
                p.Content = ActionParameterConverter.ConvertToString(taskID, p.Content);

                Debug.WriteLine("JsonDeserialize:" + p.Content);
                try
                {
                    //尝试用正则表达式取出有效范围
                    var regx = Regex.Match(p.Content, @"\{([\s\S]*)\}");
                    if (regx.Success)
                    {
                        p.Content = regx.Value;
                    }
                    result.Result[-1] = JsonConvert.DeserializeObject <object>(p.Content);
                    result.Result[(int)CommonResultKeyType.IsSuccess] = true;
                }
                catch (Exception e)
                {
                    LogHelper.Error(e.ToString());
                }
                //返回数据
                ActionTaskResulter.Add(taskID, result);
                OnEventStateChanged?.Invoke(taskID, action.ID, ActionInvokeStateType.Done);
            });
        }
Esempio n. 6
0
        public System.Action GenerateAction(int taskID, ActionModel action)
        {
            return(() =>
            {
                var p = ObjectConvert.Get <StartProcessActionParamsModel>(action.Parameter);
                var result = new ActionResultModel();
                result.ID = action.ID;
                result.Result = new Dictionary <int, string>();
                result.Result.Add((int)StartProcessResultType.IsSuccess, "false");
                result.Result.Add((int)StartProcessResultType.Handle, "");
                result.Result.Add((int)StartProcessResultType.Id, "");
                p.Path = ActionParameterConverter.ConvertToString(taskID, p.Path);
                p.Args = ActionParameterConverter.ConvertToString(taskID, p.Args);

                Debug.WriteLine("启动进程:" + p.Path);
                try
                {
                    ProcessStartInfo psi = new ProcessStartInfo(p.Path, p.Args);
                    var res = Process.Start(psi);
                    if (res != null)
                    {
                        result.Result[(int)StartProcessResultType.Handle] = res.Handle.ToString();
                        result.Result[(int)StartProcessResultType.Id] = res.Id.ToString();
                    }
                    result.Result[(int)StartProcessResultType.IsSuccess] = "true";
                }
                catch (Exception e)
                {
                    LogHelper.Error(e.ToString());
                }
                //返回数据
                ActionTaskResulter.Add(taskID, result);
            });
        }
Esempio n. 7
0
 public System.Action GenerateAction(int taskID, ActionModel action)
 {
     return(() =>
     {
         OnEventStateChanged?.Invoke(taskID, action.ID, ActionInvokeStateType.Runing);
         var p = ObjectConvert.Get <SoundPlayActionParamsModel>(action.Parameter);
         var result = new ActionResultModel();
         result.ID = action.ID;
         result.Result = new Dictionary <int, object>();
         result.Result.Add((int)CommonResultKeyType.IsSuccess, false);
         p.Path = ActionParameterConverter.ConvertToString(taskID, p.Path);
         try
         {
             PlaySound(p.Path);
             result.Result[(int)CommonResultKeyType.IsSuccess] = true;
         }
         catch (Exception e)
         {
             LogHelper.Error(e.ToString());
         }
         //返回数据
         ActionTaskResulter.Add(taskID, result);
         OnEventStateChanged?.Invoke(taskID, action.ID, ActionInvokeStateType.Done);
     });
 }
Esempio n. 8
0
 public System.Action GenerateAction(int taskID, ActionModel action)
 {
     return(() =>
     {
         var p = ObjectConvert.Get <SnippingActionParamsModel>(action.Parameter);
         var result = new ActionResultModel();
         result.ID = action.ID;
         result.Result = new Dictionary <int, string>();
         result.Result.Add((int)SnippingResultType.IsSuccess, "false");
         result.Result.Add((int)SnippingResultType.SavePath, p.SavePath);
         p.SavePath = ActionParameterConverter.ConvertToString(taskID, p.SavePath);
         try
         {
             var sr = CommonWin32API.GetScreenResolution();
             Bitmap bitmap = new Bitmap(sr.Width, sr.Height);
             Graphics graphics = Graphics.FromImage(bitmap);
             graphics.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(sr.Width, sr.Height));
             EncoderParameters encoderParams = new EncoderParameters();
             EncoderParameter encoderParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, new long[] { 100 });
             encoderParams.Param[0] = encoderParam;
             var codecInfo = ImageCodecInfo.GetImageEncoders().FirstOrDefault(ici => ici.MimeType == "image/jpeg");
             bitmap.Save(p.SavePath, codecInfo, encoderParams);
             result.Result[(int)SnippingResultType.IsSuccess] = "true";
         }
         catch (Exception e)
         {
             LogHelper.Error(e.ToString());
         }
         //返回数据
         ActionTaskResulter.Add(taskID, result);
     });
 }
        public System.Action GenerateAction(int taskID, ActionModel action)
        {
            return(() =>
            {
                OnEventStateChanged?.Invoke(taskID, action.ID, ActionInvokeStateType.Runing);
                var p = ObjectConvert.Get <RegexActionParamsModel>(action.Parameter);
                var result = new ActionResultModel();
                result.ID = action.ID;
                result.Result = new Dictionary <int, object>();
                result.Result.Add((int)RegexResultType.Count, "0");
                p.Content = ActionParameterConverter.ConvertToString(taskID, p.Content);

                try
                {
                    var matchs = Regex.Matches(p.Content, p.Regex);
                    int i = 0;
                    foreach (Match match in matchs)
                    {
                        result.Result.Add(i, match.Value);
                        i++;
                    }
                    result.Result[(int)RegexResultType.Count] = matchs.Count.ToString();
                }
                catch (Exception e)
                {
                    LogHelper.Error(e.ToString());
                }
                //返回数据
                ActionTaskResulter.Add(taskID, result);
                OnEventStateChanged?.Invoke(taskID, action.ID, ActionInvokeStateType.Done);
            });
        }
        public System.Action GenerateAction(int taskID, ActionModel action)
        {
            return(() =>
            {
                OnEventStateChanged?.Invoke(taskID, action.ID, ActionInvokeStateType.Runing);
                var p = ObjectConvert.Get <DownloadFileParamsModel>(action.Parameter);
                p.Url = ActionParameterConverter.ConvertToString(taskID, p.Url);
                p.SavePath = ActionParameterConverter.ConvertToString(taskID, p.SavePath);

                var result = new ActionResultModel();
                result.ID = action.ID;
                result.Result = new Dictionary <int, object>();
                result.Result.Add((int)DownloadFileResultType.IsSuccess, false);
                result.Result.Add((int)DownloadFileResultType.SavePath, p.SavePath);
                try
                {
                    var wc = new WebClient();
                    foreach (var item in p.Headers)
                    {
                        wc.Headers.Add(item.Key, item.Value);
                    }
                    wc.DownloadFile(p.Url, p.SavePath);
                    result.Result[(int)DownloadFileResultType.IsSuccess] = true;
                }
                catch (Exception e)
                {
                    LogHelper.Error(e.ToString());
                }
                //返回数据
                ActionTaskResulter.Add(taskID, result);
                OnEventStateChanged?.Invoke(taskID, action.ID, ActionInvokeStateType.Done);
            });
        }
Esempio n. 11
0
        public System.Action GenerateAction(int taskID, ActionModel action)
        {
            return(() =>
            {
                OnEventStateChanged?.Invoke(taskID, action.ID, ActionInvokeStateType.Runing);
                var p = ObjectConvert.Get <GetIPAddressActionParamsModel>(action.Parameter);
                var result = new ActionResultModel();
                result.ID = action.ID;
                result.Result = new Dictionary <int, object>();
                result.Result.Add((int)GetIPAddressResultType.IsSuccess, false);
                result.Result.Add((int)GetIPAddressResultType.IP, string.Empty);
                try
                {
                    if (p.Type == Core.Types.IPAddressType.LocalIPV4)
                    {
                        //获取内网ipv4
                        var host = Dns.GetHostEntry(Dns.GetHostName());
                        string ipaddress = string.Empty;
                        foreach (var ip in host.AddressList)
                        {
                            if (ip.AddressFamily == AddressFamily.InterNetwork)
                            {
                                ipaddress = ip.ToString();
                            }
                        }
                        if (!string.IsNullOrEmpty(ipaddress))
                        {
                            result.Result[(int)GetIPAddressResultType.IsSuccess] = true;
                            result.Result[(int)GetIPAddressResultType.IP] = ipaddress;
                        }
                    }
                    else if (p.Type == Core.Types.IPAddressType.PublicIPV4 && System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
                    {
                        //获取公网ipv4
                        var httprequest = new HttpRequest();
                        httprequest.Url = "https://202020.ip138.com/";
                        httprequest.Headers = new Dictionary <string, string>();
                        httprequest.Headers.Add("User-Agent", "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1");

                        string html = httprequest.GetAsync().Result.Content;
                        var reg = Regex.Match(html, @"(?<ip>(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d))");
                        if (reg.Success && !string.IsNullOrEmpty(reg.Groups["ip"].Value))
                        {
                            result.Result[(int)GetIPAddressResultType.IsSuccess] = true;
                            result.Result[(int)GetIPAddressResultType.IP] = reg.Groups["ip"].Value;
                        }
                    }
                }
                catch (Exception e)
                {
                    LogHelper.Error(e.ToString());
                }
                //返回数据
                ActionTaskResulter.Add(taskID, result);
                OnEventStateChanged?.Invoke(taskID, action.ID, ActionInvokeStateType.Done);
            });
        }
Esempio n. 12
0
        public System.Action GenerateAction(int taskID, ActionModel action)
        {
            return(() =>
            {
                bool isPass = false;
                var p = ObjectConvert.Get <IFActionParameterModel>(action.Parameter);
                string left, right;
                //获取左输入
                left = ActionParameterConverter.ConvertToString(taskID, p.LeftInput);
                //获取右输入
                right = ActionParameterConverter.ConvertToString(taskID, p.RightInput);


                switch (p.Condition)
                {
                case Types.IFActionConditionType.Equal:
                    isPass = left == right;
                    break;

                case Types.IFActionConditionType.UnEqual:
                    isPass = left != right;
                    break;

                case Types.IFActionConditionType.Has:
                    isPass = left.IndexOf(right) != -1;
                    break;

                case Types.IFActionConditionType.Miss:
                    isPass = left.IndexOf(right) == -1;
                    break;
                }

                if (isPass)
                {
                    ActionTask.Invoke(taskID, p.PassActions, taskID == ActionTask.TestTaskID, true);
                }
                else
                {
                    ActionTask.Invoke(taskID, p.NoPassActions, taskID == ActionTask.TestTaskID, true);
                }

                var result = new ActionResultModel();
                result.ID = action.ID;
                result.Result = new Dictionary <int, string>();
                result.Result.Add((int)CommonResultKeyType.IsSuccess, isPass.ToString());
                //result.Result = new Dictionary<int, ActionResultValueModel>();
                //result.Result.Add((int)CommonResultKeyType.Status, new ActionResultValueModel()
                //{
                //    Type = ActoinResultValueType.BOOL,
                //    Value = isPass
                //});
                //返回数据
                ActionTaskResulter.Add(taskID, result);
            });
        }
Esempio n. 13
0
 private void PipeCallFunction_OnCallFeedback(PipeCallFunctionFeedbackStruct fb)
 {
     if (fb.ID == callID)
     {
         var result = new ActionResultModel();
         result.ID     = actionID;
         result.Result = new Dictionary <int, object>();
         result.Result.Add((int)DialogResultType.ClickButtonValue, fb.FeedbackData.ToString());
         //返回数据
         ActionTaskResulter.Add(taskID, result);
         OnEventStateChanged?.Invoke(taskID, actionID, ActionInvokeStateType.Done);
     }
 }
        public System.Action GenerateAction(int taskID, ActionModel action)
        {
            return(() =>
            {
                OnEventStateChanged?.Invoke(taskID, action.ID, ActionInvokeStateType.Runing);
                var p = ObjectConvert.Get <KillProcessActionParamsModel>(action.Parameter);
                p.ProcessName = ActionParameterConverter.ConvertToString(taskID, p.ProcessName);

                var result = new ActionResultModel();
                result.ID = action.ID;
                result.Result = new Dictionary <int, object>();
                result.Result.Add((int)CommonResultKeyType.IsSuccess, true);
                if (!string.IsNullOrEmpty(p.ProcessName))
                {
                    var processes = Process.GetProcesses();
                    List <Process> closeProcesses;
                    if (p.IsFuzzy)
                    {
                        closeProcesses = processes.Where(m => m.ProcessName.Contains(p.ProcessName)).ToList();
                    }
                    else
                    {
                        closeProcesses = processes.Where(m => m.ProcessName == p.ProcessName).ToList();
                    }
                    try
                    {
                        foreach (var item in closeProcesses)
                        {
                            item.Kill();
                        }
                        if (closeProcesses.Count == 0)
                        {
                            result.Result[(int)CommonResultKeyType.IsSuccess] = false;
                        }
                    }
                    catch
                    {
                        result.Result[(int)CommonResultKeyType.IsSuccess] = false;
                    }
                }
                else
                {
                    result.Result[(int)CommonResultKeyType.IsSuccess] = false;
                }
                ActionTaskResulter.Add(taskID, result);
                OnEventStateChanged?.Invoke(taskID, action.ID, ActionInvokeStateType.Done);
            });
        }
Esempio n. 15
0
        public System.Action GenerateAction(int taskID, ActionModel action)
        {
            return(() =>
            {
                OnEventStateChanged?.Invoke(taskID, action.ID, ActionInvokeStateType.Runing);
                var p = ObjectConvert.Get <HttpRequestActionParameterModel>(action.Parameter);
                var result = new ActionResultModel();
                result.ID = action.ID;
                result.Result = new Dictionary <int, object>();
                result.Result.Add((int)HttpResultType.IsSuccess, false);
                if (p != null)
                {
                    p.Url = ActionParameterConverter.ConvertToString(taskID, p.Url);
                    p.JsonStr = ActionParameterConverter.ConvertToString(taskID, p.JsonStr);

                    Debug.WriteLine("http request:" + p.Url);
                    var http = new HttpRequest();
                    http.Url = p.Url;
                    http.Headers = p.Headers;
                    http.Data = p.QueryParams;
                    http.Files = p.Files;
                    http.ParamsType = p.ParamsType;
                    http.JsonStr = p.JsonStr;
                    try
                    {
                        var content = p.Method == Net.Types.MethodType.GET ? http.GetAsync().Result : http.PostAsync().Result;
                        result.Result.Add((int)HttpResultType.StatusCode, content.StatusCode.ToString());
                        result.Result.Add((int)HttpResultType.Content, content.Content);
                        result.Result[(int)HttpResultType.IsSuccess] = content.IsSuccess;
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine(e.ToString());
                    }
                }

                //返回数据
                ActionTaskResulter.Add(taskID, result);
                OnEventStateChanged?.Invoke(taskID, action.ID, ActionInvokeStateType.Done);
            });
        }
Esempio n. 16
0
 public System.Action GenerateAction(int taskID, ActionModel action)
 {
     return(() =>
     {
         var result = new ActionResultModel();
         result.ID = action.ID;
         result.Result = new Dictionary <int, string>();
         result.Result.Add((int)CommonResultKeyType.IsSuccess, "false");
         try
         {
             ShutDownSys.ShutDown();
             Debug.WriteLine("执行关机");
             result.Result[(int)CommonResultKeyType.IsSuccess] = "true";
         }
         catch
         {
         }
         //返回数据
         ActionTaskResulter.Add(taskID, result);
     });
 }
 public System.Action GenerateAction(int taskID, ActionModel action)
 {
     return(() =>
     {
         OnEventStateChanged?.Invoke(taskID, action.ID, ActionInvokeStateType.Runing);
         var result = new ActionResultModel();
         result.ID = action.ID;
         result.Result = new Dictionary <int, object>();
         result.Result.Add((int)CommonResultKeyType.IsSuccess, false);
         try
         {
             ShutDownSys.ShutDown();
             Debug.WriteLine("执行关机");
             result.Result[(int)CommonResultKeyType.IsSuccess] = true;
         }
         catch
         {
         }
         //返回数据
         ActionTaskResulter.Add(taskID, result);
         OnEventStateChanged?.Invoke(taskID, action.ID, ActionInvokeStateType.Done);
     });
 }
Esempio n. 18
0
 public System.Action GenerateAction(int taskID, ActionModel action)
 {
     return(() =>
     {
         var p = ObjectConvert.Get <SoundPlayActionParamsModel>(action.Parameter);
         var result = new ActionResultModel();
         result.ID = action.ID;
         result.Result = new Dictionary <int, string>();
         result.Result.Add((int)CommonResultKeyType.IsSuccess, "false");
         p.Path = ActionParameterConverter.ConvertToString(taskID, p.Path);
         try
         {
             PlaySound(p.Path);
             result.Result[(int)CommonResultKeyType.IsSuccess] = "true";
         }
         catch (Exception e)
         {
             LogHelper.Error(e.ToString());
         }
         //返回数据
         ActionTaskResulter.Add(taskID, result);
     });
 }