Exemplo n.º 1
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);
            });
        }
Exemplo 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);
     });
 }
Exemplo n.º 3
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());
                }
            });
        }
        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);
            });
        }
Exemplo n.º 5
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);
            });
        }
Exemplo n.º 6
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);
            });
        }
Exemplo 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);
     });
 }
Exemplo n.º 8
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);
            });
        }
Exemplo n.º 9
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);
            });
        }
Exemplo n.º 11
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);
            });
        }
Exemplo 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);
            });
        }
 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);
     });
 }
        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);
     });
 }
Exemplo n.º 16
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);
            });
        }
Exemplo n.º 17
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);
     });
 }