Exemplo n.º 1
0
 public TaskStates Update(float arg)
 {
     string result = "";
     if(activeTasks != null && tasksText != null) {
         timer += arg;
         result += "Time : " + (int)(taskTime - timer) + "\n";
         foreach(string task in tasksBuffer) {
             result += task + "\n";
         }
         tasksText.text = result;
     }
     if(timer > taskTime) {
         state = TaskStates.FAIL;
     }
     return state;
 }
Exemplo n.º 2
0
 public void setStarted()
 {
     state = TaskStates.IN_PROCESS;
 }
Exemplo n.º 3
0
 public void StartTask(int arg)
 {
     id = arg;
     InitDefault(id);
     state = TaskStates.NEW;
     clearPlayerPrefs();
 }
Exemplo n.º 4
0
    public Tasks(int arg_id, GameObject arg_go)
    {
        id = arg_id;
        if(arg_go != null) {
            tasksText = (GUIText)arg_go.GetComponent(typeof(GUIText));
        }

        InitTasks();
        InitDefault(id);
        state = TaskStates.NONE;
    }
Exemplo n.º 5
0
 public void CheckTasks()
 {
     if(tasksBuffer != null) {
         tasksBuffer.Clear();
     } else {
         tasksBuffer = new ArrayList();
     }
     state = TaskStates.IN_PROCESS;
     if(activeTasks != null) {
         int activeTasksCount = 0;
         foreach(Task task in activeTasks) {
             if(!task.Check(fishesInfo)) {
                 tasksBuffer.Add(task.getTitle(fishesInfo));
                 activeTasksCount++;
             }
         }
         if(activeTasksCount <= 0) {
             state = TaskStates.COMPLETE;
         }
     } else {
         state = TaskStates.NONE;
     }
 }
 /// <summary>
 /// Performs a state transition on the task.
 /// </summary>
 /// <param name="state">The task's new state.</param>
 /// <exception cref="TaskStateInvalidException">
 /// thrown if the task is in a state that makes the state transition
 /// invalid.</exception>
 protected void SetTaskState(TaskStates state)
 {
     switch (state)
     {
         case TaskStates.Pending:
             AssertState(TaskStates.Idle);
             break;
         case TaskStates.PendingScheduled:
             AssertState(TaskStates.Idle);
             break;
         case TaskStates.PendingCancel:
         case TaskStates.Executing:
             AssertState(TaskStates.Pending, TaskStates.PendingScheduled);
             break;
         case TaskStates.Yielding:
         case TaskStates.Completed:
         case TaskStates.CompletedSuccess:
             AssertState(TaskStates.Executing);
             break;
         case TaskStates.CompletedWithError:
             AssertState(TaskStates.PendingScheduled, TaskStates.Yielding, TaskStates.Executing);
             break;
         case TaskStates.CompletedCanceled:
             AssertState(TaskStates.PendingCancel);
             break;
         case TaskStates.Idle:
         default:
             throw new ArgumentOutOfRangeException();
     }
     _taskState.SetState(state);
 }
Exemplo n.º 7
0
 public ActionResult List(TaskStates state)
 {
     var workers = Scheduler.LoadWorkers().Where(w => w.State.Equals(state));
     ViewBag.TaskState = state;
     return PartialView(workers);
 }
Exemplo n.º 8
0
        /// <summary>
        /// Put the work item to work.
        /// </summary>
        public void Run()
        {
            this.State = TaskStates.Running;
            if (job == null)
                job = GetJob();

            try
            {
                job.Execute();
                this.LastRunTime = DateTime.Now;
            }
            catch (Exception e)
            {
                this.State = TaskStates.Stop;

                //Fail and retry ? Should we need to handle the retry ?
                job.OnError(e);
                Logger.Error(e);
            }

            //Counter++;
            if (Frequency == Frequencies.OneTime)
                this.State = TaskStates.Completed;
            else
            {
                StartAt = NextStart;
                this.State = TaskStates.Ready;
                NextStart = GetNextStart(StartAt);
            }
            this.Save();
        }
Exemplo n.º 9
0
        /// <summary>
        /// Read properties from specified url.
        /// </summary>
        /// <param name="url"></param>
        public void Read(string url)
        {
            var xmlDoc = XDocument.Load(url);
            var ns = xmlDoc.Root.GetDefaultNamespace();

            DateTime startAt = DateTime.MinValue;
            DateTime nextStart = DateTime.MinValue;
            var root = xmlDoc.Root;
            CommandData = new Dictionary<string, object>();
            DateTime.TryParse(root.Element(ns + "startAt").Value, out startAt);
            DateTime.TryParse(root.Element(ns + "nextStart").Value, out nextStart);

            var fstr = root.Element(ns + "recurs").StrAttr("frequency");

            if (string.IsNullOrEmpty(this.Name))
                this.Name= System.IO.Path.GetFileNameWithoutExtension(url);

            this.Frequency = !string.IsNullOrEmpty(fstr) ? (Frequencies)Enum.Parse(typeof(Frequencies), fstr) : Frequencies.Minutely;
            this.JobType = Type.GetType(root.Element(ns + "command").StrAttr("type"));
            this.Recurs = root.Element(ns + "recurs").IntAttr("value");

            if (root.Element(ns + "title") != null)
                this.Title = root.Element(ns + "title").Value;

            if (root.Element(ns + "desc") != null)
                this.Description = root.Element(ns + "desc").Value;

            if (root.Element(ns + "state") != null)
            {
                var stateStr = root.Element(ns + "state").Value;
                if (!string.IsNullOrEmpty(stateStr))
                {
                    this.State = (TaskStates)Enum.Parse(typeof(TaskStates), stateStr);
                }
            }

            var recurringDaysOfWeek = root.Element(ns + "recurs").StrAttr("daysOfWeek");
            var recurringDaysOfMonth = root.Element(ns + "recurs").StrAttr("daysOfMonth");
            var recurringMonths = root.Element(ns + "recurs").StrAttr("months");

            if (!string.IsNullOrEmpty(recurringDaysOfWeek))
                this.RecurringDaysOfWeek = recurringDaysOfWeek.Split(',').Select(a => Convert.ToInt32(a)).ToArray();

            if (!string.IsNullOrEmpty(recurringDaysOfMonth))
                this.RecurringDaysOfWeek = recurringDaysOfMonth.Split(',').Select(a => Convert.ToInt32(a)).ToArray();

            if (!string.IsNullOrEmpty(recurringMonths))
                this.RecurringMonths = recurringMonths.Split(',').Select(a => Convert.ToInt32(a)).ToArray();

            foreach (var param in root.Element(ns + "command").Elements())
                CommandData.Add(param.StrAttr("name"), param.Value);

            this.StartAt = startAt;
            this.NextStart = nextStart;
            this.File = url;
        }
 private static String FormatMessage(TaskStates current, params TaskStates[] expected)
 {
     Contracts.Require.AtLeastOneParam<TaskStates>("expected", expected);
     String sexp = expected[0].ToString();
     for (int i = 0; i < expected.Length; ++i)
     {
         if (i == expected.Length - 1)
             sexp += "or " + expected[i].ToString();
         else
             sexp += ", " + expected[i].ToString();
     }
     return String.Format(Properties.Resources.Error_TaskStateInvalidExpect, sexp, current);
 }
 public TaskStateInvalidException(TaskStates current, params TaskStates[] expected)
     : base(TaskStateInvalidException.FormatMessage(current, expected))
 {
 }
Exemplo n.º 12
0
        private static void ApplyStatusFilter(NameValueCollection query, TaskStates statusFilter)
        {
            var statesToCheck = new[] {TaskStates.Queued, TaskStates.Running, TaskStates.Complete, TaskStates.Error, TaskStates.Cancelled, TaskStates.Killed, TaskStates.Timeout};

            foreach (TaskStates state in statesToCheck.Where(x => statusFilter.HasFlag(x)))
            {
                query.Add(Convert.ToString(state).ToLower(), "1");
            }
        }