예제 #1
0
 private void checkAddTask(TaskDesc current_task)
 {
     if (current_task != null)
     {
         //Check if we built a valid task before adding it
         if (Script.LookForScript(ref current_task.script_file)) //Check if file exists
         {
             if (current_task.script_file != null &&
                 (current_task.triggerOnLogin ||
                  current_task.triggerOnFirstLogin ||
                  (current_task.triggerOnTime && current_task.triggerOnTime_Times.Count > 0)) ||
                 (current_task.triggerOnInterval && current_task.triggerOnInterval_Interval > 0))    //Look for a valid trigger
             {
                 if (Settings.DebugMessages)
                 {
                     LogToConsole("Loaded task:\n" + Task2String(current_task));
                 }
                 current_task.triggerOnInterval_Interval_Countdown = current_task.triggerOnInterval_Interval; //Init countdown for interval
                 tasks.Add(current_task);
             }
             else if (Settings.DebugMessages)
             {
                 LogToConsole("This task will never trigger:\n" + Task2String(current_task));
             }
         }
         else if (Settings.DebugMessages)
         {
             LogToConsole("No valid script for task:\n" + Task2String(current_task));
         }
     }
 }
예제 #2
0
        public override void Initialize()
        {
            //Load the given file from the startup parameters
            if (System.IO.File.Exists(tasksfile))
            {
                LogDebugToConsoleTranslated("bot.scriptScheduler.loading", System.IO.Path.GetFullPath(tasksfile));
                TaskDesc current_task = null;
                String[] lines        = System.IO.File.ReadAllLines(tasksfile, Encoding.UTF8);
                foreach (string lineRAW in lines)
                {
                    string line = lineRAW.Split('#')[0].Trim();
                    if (line.Length > 0)
                    {
                        if (line[0] == '[' && line[line.Length - 1] == ']')
                        {
                            switch (line.Substring(1, line.Length - 2).ToLower())
                            {
                            case "task":
                                checkAddTask(current_task);
                                current_task = new TaskDesc();     //Create a blank task
                                break;
                            }
                        }
                        else if (current_task != null)
                        {
                            string argName = line.Split('=')[0];
                            if (line.Length > (argName.Length + 1))
                            {
                                string argValue = line.Substring(argName.Length + 1);
                                switch (argName.ToLower())
                                {
                                case "triggeronfirstlogin": current_task.triggerOnFirstLogin = Settings.str2bool(argValue); break;

                                case "triggeronlogin": current_task.triggerOnLogin = Settings.str2bool(argValue); break;

                                case "triggerontime": current_task.triggerOnTime = Settings.str2bool(argValue); break;

                                case "triggeroninterval": current_task.triggerOnInterval = Settings.str2bool(argValue); break;

                                case "timevalue": try { current_task.triggerOnTime_Times.Add(DateTime.ParseExact(argValue, "HH:mm", CultureInfo.InvariantCulture)); } catch { } break;

                                case "timeinterval": int interval = 1; int.TryParse(argValue, out interval); current_task.triggerOnInterval_Interval = interval; break;

                                case "script": current_task.action = "script " + argValue; break;     //backward compatibility with older tasks.ini

                                case "action": current_task.action = argValue; break;
                                }
                            }
                        }
                    }
                }
                checkAddTask(current_task);
            }
            else
            {
                LogToConsoleTranslated("bot.scriptScheduler.not_found", System.IO.Path.GetFullPath(tasksfile));
                UnloadBot(); //No need to keep the bot active
            }
        }
예제 #3
0
 private static string Task2String(TaskDesc task)
 {
     return(Translations.Get(
                "bot.scriptScheduler.task",
                task.triggerOnFirstLogin,
                task.triggerOnLogin,
                task.triggerOnTime,
                task.triggerOnInterval,
                String.Join(", ", task.triggerOnTime_Times),
                task.triggerOnInterval_Interval,
                task.action
                ));
 }
        private void PublishGlobalVars(IActionContext actionContext, bool success, TaskDesc taskDesc)
        {
            if (success)
            {
                PublishGlobalVars(actionContext, taskDesc.TaskInfo.OnSuccess);
            }
            else
            {
                PublishGlobalVars(actionContext, taskDesc.TaskInfo.OnError);
            }

            PublishGlobalVars(actionContext, taskDesc.TaskInfo.OnComplete);
        }
예제 #5
0
 private static string Task2String(TaskDesc task)
 {
     return(String.Format(
                " triggeronfirstlogin = {0}\n triggeronlogin = {1}\n triggerontime = {2}\n "
                + "triggeroninterval = {3}\n timevalue = {4}\n timeinterval = {5}\n script = {6}",
                task.triggerOnFirstLogin,
                task.triggerOnLogin,
                task.triggerOnTime,
                task.triggerOnInterval,
                String.Join(", ", task.triggerOnTime_Times),
                task.triggerOnInterval_Interval,
                task.script_file
                ));
 }
예제 #6
0
 public override void Initialize()
 {
     //Load the given file from the startup parameters
     if (System.IO.File.Exists(tasksfile))
     {
         TaskDesc current_task = null;
         String[] lines = System.IO.File.ReadAllLines(tasksfile);
         foreach (string lineRAW in lines)
         {
             string line = lineRAW.Split('#')[0].Trim();
             if (line.Length > 0)
             {
                 if (line[0] == '[' && line[line.Length - 1] == ']')
                 {
                     switch (line.Substring(1, line.Length - 2).ToLower())
                     {
                         case "task":
                             checkAddTask(current_task);
                             current_task = new TaskDesc(); //Create a blank task
                             break;
                     }
                 }
                 else if (current_task != null)
                 {
                     string argName = line.Split('=')[0];
                     if (line.Length > (argName.Length + 1))
                     {
                         string argValue = line.Substring(argName.Length + 1);
                         switch (argName.ToLower())
                         {
                             case "triggeronfirstlogin": current_task.triggerOnFirstLogin = Settings.str2bool(argValue); break;
                             case "triggeronlogin": current_task.triggerOnLogin = Settings.str2bool(argValue); break;
                             case "triggerontime": current_task.triggerOnTime = Settings.str2bool(argValue); break;
                             case "triggeroninterval": current_task.triggerOnInterval = Settings.str2bool(argValue); break;
                             case "timevalue": try { current_task.triggerOnTime_Times.Add(DateTime.ParseExact(argValue, "HH:mm", CultureInfo.InvariantCulture)); } catch { } break;
                             case "timeinterval": int interval = 1; int.TryParse(argValue, out interval); current_task.triggerOnInterval_Interval = interval; break;
                             case "script": current_task.script_file = argValue; break;
                         }
                     }
                 }
             }
         }
         checkAddTask(current_task);
     }
     else
     {
         LogToConsole("File not found: '" + tasksfile + "'");
         UnloadBot(); //No need to keep the bot active
     }
 }
        private IExecuteContext CreateExecuteContext(IActionContext actionContext, TaskDesc taskDesc, bool isSubEntryAction)
        {
            string newid = idGenService.NewId();

            return(new ExecuteContext()
            {
                ActionFullName = taskDesc.TaskInfo.Action,
                ExecuteName = taskDesc.TaskName,
                Token = actionContext.Token,
                ActionRetryCount = taskDesc.TaskInfo.RetryCount,
                ExecutePath = actionContext.ExecutePath.NewSubPath(newid),
                ExecuteParameter = OnCreateExecuteParameter(actionContext, taskDesc, isSubEntryAction)
            });
        }
예제 #8
0
 private void checkAddTask(TaskDesc current_task)
 {
     if (current_task != null)
     {
         //Check if we built a valid task before adding it
         if (current_task.script_file != null && Script.LookForScript(ref current_task.script_file) && //Check if file exists
             (current_task.triggerOnLogin ||
              (current_task.triggerOnTime && current_task.triggerOnTime_Times.Count > 0)) ||
             (current_task.triggerOnInterval && current_task.triggerOnInterval_Interval > 0))             //Look for a valid trigger
         {
             current_task.triggerOnInterval_Interval_Countdown = current_task.triggerOnInterval_Interval; //Init countdown for interval
             tasks.Add(current_task);
         }
     }
 }
예제 #9
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (TaskID != 0)
            {
                hash ^= TaskID.GetHashCode();
            }
            if (SeqID != 0)
            {
                hash ^= SeqID.GetHashCode();
            }
            if (ExchangeMaxCount != 0)
            {
                hash ^= ExchangeMaxCount.GetHashCode();
            }
            if (TaskName.Length != 0)
            {
                hash ^= TaskName.GetHashCode();
            }
            if (TaskDesc.Length != 0)
            {
                hash ^= TaskDesc.GetHashCode();
            }
            if (ExchangeTargetID != 0)
            {
                hash ^= ExchangeTargetID.GetHashCode();
            }
            if (ExchangeTargetNum != 0)
            {
                hash ^= ExchangeTargetNum.GetHashCode();
            }
            hash ^= actConsumeRes_.GetHashCode();
            if (ResetType != 0)
            {
                hash ^= ResetType.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
예제 #10
0
            public static string GenerateTaskDesc(string filedir, string filename, TaskDesc tdsc)
            {
                JsonSerializer serializer = new JsonSerializer();

                serializer.NullValueHandling = NullValueHandling.Ignore;
                string taskdesc = Path.Combine(filedir, filename + ".dsc");

                using (StreamWriter sw = new StreamWriter(taskdesc))
                {
                    using (JsonWriter jw = new JsonTextWriter(sw))
                    {
                        serializer.Serialize(jw, new TaskDesc(taskdesc,
                                                              tdsc.rectRoi, tdsc.rectRoiF, tdsc.rectRoiPts, tdsc.rectRoiSize,
                                                              tdsc.rectBlk, tdsc.rectBlkF, tdsc.rectBlkPts, tdsc.rectBlkSize,
                                                              tdsc.slideid));
                    }
                }
                return(filedir);
            }
        public override int GetHashCode()
        {
            int hash = 1;

            if (TaskID != 0)
            {
                hash ^= TaskID.GetHashCode();
            }
            if (SeqID != 0)
            {
                hash ^= SeqID.GetHashCode();
            }
            if (MaxDoneCount != 0)
            {
                hash ^= MaxDoneCount.GetHashCode();
            }
            if (MulCondType != 0)
            {
                hash ^= MulCondType.GetHashCode();
            }
            if (TaskName.Length != 0)
            {
                hash ^= TaskName.GetHashCode();
            }
            if (TaskDesc.Length != 0)
            {
                hash ^= TaskDesc.GetHashCode();
            }
            if (FinishConditionID != 0)
            {
                hash ^= FinishConditionID.GetHashCode();
            }
            if (TargetProcess != 0)
            {
                hash ^= TargetProcess.GetHashCode();
            }
            hash ^= actMulCondTaskAward_.GetHashCode();
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
예제 #12
0
 private void checkAddTask(TaskDesc current_task)
 {
     if (current_task != null)
     {
         //Check if we built a valid task before adding it
         if (current_task.script_file != null && Script.LookForScript(ref current_task.script_file) //Check if file exists
             && (current_task.triggerOnLogin
             || (current_task.triggerOnTime && current_task.triggerOnTime_Times.Count > 0))
             || (current_task.triggerOnInterval && current_task.triggerOnInterval_Interval > 0)) //Look for a valid trigger
         {
             current_task.triggerOnInterval_Interval_Countdown = current_task.triggerOnInterval_Interval; //Init countdown for interval
             tasks.Add(current_task);
         }
     }
 }
        protected virtual IExecuteParameter OnCreateExecuteParameter(IActionContext actionContext, TaskDesc taskDesc, bool isSubEntryAction)
        {
            _ = actionContext ?? throw new ArgumentNullException(nameof(actionContext));
            _ = taskDesc ?? throw new ArgumentNullException(nameof(taskDesc));
            Dictionary <string, object> inputs = new Dictionary <string, object>();

            if (taskDesc.TaskInfo.Inputs != null)
            {
                foreach (var inputEntry in taskDesc.TaskInfo.Inputs)
                {
                    object value = dynamicValueService.GetDynamicValue(inputEntry.Value, actionContext.Parameters);
                    inputs.Add(inputEntry.Key, value);
                }
            }
            var executeParameter = new ExecuteParameter();

            executeParameter.Inputs     = new ReadOnlyDictionary <string, object>(inputs);
            executeParameter.Context    = actionContext.Parameters.Context;
            executeParameter.GlobalVars = isSubEntryAction ? actionContext.Parameters.GlobalVars : new ConcurrentDictionary <string, object>();
            if (isSubEntryAction)
            {
                var newVars = new ConcurrentDictionary <string, object>(actionContext.Parameters.Vars);
                newVars[workflowOption.SubEntryActionVarName] = taskDesc.TaskInfo;
                executeParameter.Vars = newVars;
            }
            else
            {
                executeParameter.Vars = new ConcurrentDictionary <string, object>();
            }
            return(executeParameter);
        }
        private List <TaskDesc> GetNextTasks(IActionContext actionContext, bool success, TaskDesc taskDesc, GroupInfo groupInfo)
        {
            List <string> allNextTasksNames = new List <string>();

            if (success)
            {
                allNextTasksNames.AddRange(GetNextTasksFromNextChain(actionContext, taskDesc.TaskInfo.OnSuccess));
            }
            else
            {
                allNextTasksNames.AddRange(GetNextTasksFromNextChain(actionContext, taskDesc.TaskInfo.OnError));
            }
            allNextTasksNames.AddRange(GetNextTasksFromNextChain(actionContext, taskDesc.TaskInfo.OnComplete));
            return(GetRunTasks(taskDesc.TaskName, allNextTasksNames, groupInfo));
        }
 private void PublishResultVars(IActionContext actionContext, IExecuteResult result, TaskDesc taskDesc)
 {
     publishValueService.PublishVars($"{taskDesc.TaskName}_result", result.Result, actionContext.Parameters);
     publishValueService.PublishVars($"{taskDesc.TaskName}_error", result.ExecuteError, actionContext.Parameters);
     //publishValueService.PublishVar($"{taskDesc.TaskName}_log", result., actionContext.Parameters);
 }
예제 #16
0
 private void checkAddTask(TaskDesc current_task)
 {
     if (current_task != null)
     {
         //Check if we built a valid task before adding it
         if (current_task.script_file != null && Script.lookForScript(ref current_task.script_file) //Check if file exists
             && (current_task.triggerOnLogin || (current_task.triggerOnTime && current_task.triggerOnTime_Times.Count > 0))) //Look for a valid trigger
         {
             tasks.Add(current_task);
         }
     }
 }