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);
            });
        }
Ejemplo n.º 2
0
        public System.Action GenerateAction(int taskID, ActionModel action)
        {
            this.taskID = taskID;
            actionID    = action.ID;
            return(() =>
            {
                OnEventStateChanged?.Invoke(taskID, action.ID, ActionInvokeStateType.Runing);
                var p = ObjectConvert.Get <DialogActionParamsModel>(action.Parameter);
                p.Title = ActionParameterConverter.ConvertToString(taskID, p.Title);
                p.Content = ActionParameterConverter.ConvertToString(taskID, p.Content);
                p.Image = ActionParameterConverter.ConvertToString(taskID, p.Image);

                try
                {
                    callID = new Random().Next(9999) + DateTime.Now.Second;
                    PipeCallFunction.Call(new Structs.PipeCallFunctionStruct()
                    {
                        ID = callID,
                        CallFunctionType = UI.Types.PipeCallFunctionType.Dialog,
                        Data = p
                    });
                    PipeCallFunction.OnCallFeedback += PipeCallFunction_OnCallFeedback;
                }
                catch (Exception e)
                {
                    OnEventStateChanged?.Invoke(taskID, actionID, ActionInvokeStateType.Done);
                    LogHelper.Error(e.ToString());
                }
            });
        }
Ejemplo n.º 3
0
 public System.Action GenerateAction(int taskID, ActionModel action)
 {
     return(() =>
     {
         OnEventStateChanged?.Invoke(taskID, action.ID, ActionInvokeStateType.Runing);
         var p = ObjectConvert.Get <OpenURLActionParamsModel>(action.Parameter);
         var result = new ActionResultModel();
         result.ID = action.ID;
         result.Result = new Dictionary <int, object>();
         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);
         OnEventStateChanged?.Invoke(taskID, action.ID, ActionInvokeStateType.Done);
     });
 }
Ejemplo n.º 4
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);
            });
        }
Ejemplo n.º 5
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);
            });
        }
        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);
            });
        }
Ejemplo 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);
     });
 }
Ejemplo n.º 8
0
        public System.Action GenerateAction(int taskID, ActionModel action)
        {
            return(() =>
            {
                OnEventStateChanged?.Invoke(taskID, action.ID, ActionInvokeStateType.Runing);
                var p = ObjectConvert.Get <SystemNotificationActionParamsModel>(action.Parameter);
                p.Title = ActionParameterConverter.ConvertToString(taskID, p.Title);
                p.Content = ActionParameterConverter.ConvertToString(taskID, p.Content);
                p.Icon = ActionParameterConverter.ConvertToString(taskID, p.Icon);
                p.Url = ActionParameterConverter.ConvertToString(taskID, p.Url);

                try
                {
                    NotificationService notificationService = new NotificationService();
                    notificationService.ShowNotification(p.Title, p.Content, p.ToastScenarioType, p.Icon, p.ToastActionType, p.Url);
                }
                catch (Exception e)
                {
                    LogHelper.Error(e.ToString());
                }
                //返回数据
                //ActionTaskResulter.Add(taskID, result);
                OnEventStateChanged?.Invoke(taskID, action.ID, ActionInvokeStateType.Done);
            });
        }
Ejemplo n.º 9
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);
            });
        }
 public System.Action GenerateAction(int taskID, ActionModel action)
 {
     return(() =>
     {
         OnEventStateChanged?.Invoke(taskID, action.ID, ActionInvokeStateType.Runing);
         var p = ObjectConvert.Get <SnippingActionParamsModel>(action.Parameter);
         var result = new ActionResultModel();
         result.ID = action.ID;
         result.Result = new Dictionary <int, object>();
         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);
         OnEventStateChanged?.Invoke(taskID, action.ID, ActionInvokeStateType.Done);
     });
 }
Ejemplo 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);
            });
        }
 public System.Action GenerateAction(int taskID, ActionModel action)
 {
     return(() =>
     {
         OnEventStateChanged?.Invoke(taskID, action.ID, ActionInvokeStateType.Runing);
         var p = ObjectConvert.Get <DelayActionParamsModel>(action.Parameter);
         Task.Delay(p.Seconds * 1000).Wait();
         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 <SetDeviceVolumeActionParamsModel>(action.Parameter);
         p.Volume = ActionParameterConverter.ConvertToString(taskID, p.Volume);
         AudioHelper.SetMasterVolume(int.Parse(p.Volume));
         OnEventStateChanged?.Invoke(taskID, action.ID, ActionInvokeStateType.Done);
     });
 }
Ejemplo n.º 14
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);
            });
        }
 public System.Action GenerateAction(int taskID, ActionModel action)
 {
     return(() =>
     {
         OnEventStateChanged?.Invoke(taskID, action.ID, ActionInvokeStateType.Runing);
         var p = ObjectConvert.Get <KeyboardActionParamsModel>(action.Parameter);
         var result = new ActionResultModel();
         result.ID = action.ID;
         result.Result = new Dictionary <int, object>();
         //result.Result.Add((int)SnippingResultType.IsSuccess, "false");
         p.Keys = ActionParameterConverter.ConvertToString(taskID, p.Keys);
         try
         {
             if (p.Keys.Contains("+"))
             {
                 //组合键
                 var keysgroup = p.Keys.Split('+');
                 foreach (var item in keysgroup)
                 {
                     string key = item.Substring(0, 1).ToUpper() + item.Substring(1);
                     KeyboardWin32API.Press(key);
                 }
                 foreach (var item in keysgroup)
                 {
                     string key = item.Substring(0, 1).ToUpper() + item.Substring(1);
                     KeyboardWin32API.Up(key);
                 }
             }
             else
             {
                 //单键
                 p.Keys = p.Keys.Substring(0, 1).ToUpper() + p.Keys.Substring(1);
                 KeyboardWin32API.Press(p.Keys);
                 KeyboardWin32API.Up(p.Keys);
             }
         }
         catch (Exception e)
         {
             LogHelper.Error(e.ToString());
         }
         //返回数据
         //ActionTaskResulter.Add(taskID, result);
         OnEventStateChanged?.Invoke(taskID, action.ID, ActionInvokeStateType.Done);
     });
 }
Ejemplo n.º 17
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);
            });
        }
 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);
     });
 }
Ejemplo n.º 19
0
        public System.Action GenerateAction(int taskID, ActionModel action)
        {
            return(() =>
            {
                OnEventStateChanged?.Invoke(taskID, action.ID, ActionInvokeStateType.Runing);
                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;

                case IFActionConditionType.Greater:
                case IFActionConditionType.GreaterOrEqual:
                case IFActionConditionType.Less:
                case IFActionConditionType.LessOrEqual:
                    if (IsTime(left))
                    {
                        isPass = TimeConditionCheck(left, right, p.Condition);
                    }
                    else
                    {
                        isPass = NumberConditionCheck(left, right, p.Condition);
                    }
                    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, object>();
                result.Result.Add((int)CommonResultKeyType.IsSuccess, isPass);
                //result.Result = new Dictionary<int, ActionResultValueModel>();
                //result.Result.Add((int)CommonResultKeyType.Status, new ActionResultValueModel()
                //{
                //    Type = ActoinResultValueType.BOOL,
                //    Value = isPass
                //});
                //返回数据
                ActionTaskResulter.Add(taskID, result);
                OnEventStateChanged?.Invoke(taskID, action.ID, ActionInvokeStateType.Done);
            });
        }