public void AddJob(Job j, JobStates state)
 {
     lock (JobsDictLock)
     {
         JobStatus js = new JobStatus();
         js.State = state;
         jobs.Add(j, js);
     }
 }
 public void AddJob(Job j, JobStates state)
 {
     lock (JobsDictLock)
     {
         JobStatus js = new JobStatus();
         js.State = state;
         jobs.Add(j, js);
     }
 }
Ejemplo n.º 3
0
        public Job(string name)
        {
            state = JobStates.Created;

            // set parameter
            this.name = name;

            OnFailed   = null;
            OnFinished = null;
            OnStopped  = null;
        }
Ejemplo n.º 4
0
        public Job(string name)
        {
            state = JobStates.Created;

            // set parameter
            this.name = name;

            OnFailed = null;
            OnFinished = null;
            OnStopped = null;
        }
Ejemplo n.º 5
0
        public Job(string name, Task[] tasks, Action callbackFinished, Action callbackStopped, Action callbackFailed)
        {
            state = JobStates.Created;

            // set parameter
            this.name  = name;
            this.tasks = tasks;

            OnFailed   = callbackFinished;
            OnFinished = callbackStopped;
            OnStopped  = callbackFailed;
        }
Ejemplo n.º 6
0
        public Job(string name, Task[] tasks)
        {
            state = JobStates.Created;

            // set parameter
            this.name  = name;
            this.tasks = tasks;

            OnFailed   = null;
            OnFinished = null;
            OnStopped  = null;
        }
Ejemplo n.º 7
0
        public Job(string name, Task[] tasks, Action callbackFinished, Action callbackStopped, Action callbackFailed)
        {
            state = JobStates.Created;

            // set parameter
            this.name = name;
            this.tasks = tasks;

            OnFailed = callbackFinished;
            OnFinished = callbackStopped;
            OnStopped = callbackFailed;
        }
Ejemplo n.º 8
0
        public Job(string name, Task[] tasks)
        {
            state = JobStates.Created;

            // set parameter
            this.name = name;
            this.tasks = tasks;

            OnFailed = null;
            OnFinished = null;
            OnStopped = null;
        }
Ejemplo n.º 9
0
        void Stopped(int taskIdx)
        {
            TimeSpan result     = DateTime.Now.Subtract(startTime);
            float    duration   = (float)result.TotalMilliseconds;
            int      frDuration = Time.frameCount - startFrame;

            Debug.Log("Job: " + name + " Stopped at task " + taskIdx + ". Time: " + duration.ToString("f2") + "ms, " + frDuration + " fr");
            tasks = null;
            state = JobStates.Done;

            if (OnStopped != null)
            {
                OnStopped();
            }
        }
Ejemplo n.º 10
0
        void Finished()
        {
            //float duration = Time.time - startTime;
            TimeSpan result     = DateTime.Now.Subtract(startTime);
            float    duration   = (float)result.TotalMilliseconds;
            int      frDuration = Time.frameCount - startFrame;

            Debug.Log("Job: " + name + " with " + tasks.Length + " tasks finished! Time: " + duration.ToString("f2") + "ms, " + frDuration + " fr");
            tasks = null;
            state = JobStates.Done;

            if (OnFinished != null)
            {
                OnFinished();
            }
        }
Ejemplo n.º 11
0
        /// <inheritdoc />
        public override bool Equals(object obj)
        {
            var other = obj as OperationalState;

            if (other == null)
            {
                return(false);
            }
            if (!base.Equals(obj))
            {
                return(false);
            }
            if (!MachineStates.SequenceEqual(other.MachineStates))
            {
                return(false);
            }
            if (CurrentJobState != other.CurrentMachineState)
            {
                return(false);
            }
            if (!JobStates.SequenceEqual(other.JobStates))
            {
                return(false);
            }
            if (CurrentJobState != other.CurrentJobState)
            {
                return(false);
            }
            if (RunningTime != other.RunningTime)
            {
                return(false);
            }
            if (RemainingTime != other.RemainingTime)
            {
                return(false);
            }
            if (ProgressPercentage != other.ProgressPercentage)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 12
0
        void Stopped(int taskIdx)
        {
            TimeSpan result = DateTime.Now.Subtract(startTime);
            float duration = (float)result.TotalMilliseconds;
            int frDuration = Time.frameCount - startFrame;
            Debug.Log("Job: " + name + " Stopped at task " + taskIdx + ". Time: " + duration.ToString("f2") + "ms, " + frDuration + " fr");
            tasks = null;
            state = JobStates.Done;

            if (OnStopped != null)
                OnStopped();
        }
Ejemplo n.º 13
0
        void Finished()
        {
            //float duration = Time.time - startTime;
            TimeSpan result = DateTime.Now.Subtract(startTime);
            float duration = (float)result.TotalMilliseconds;
            int frDuration = Time.frameCount - startFrame;
            Debug.Log("Job: " + name + " with " + tasks.Length + " tasks finished! Time: " + duration.ToString("f2") + "ms, " + frDuration + " fr");
            tasks = null;
            state = JobStates.Done;

            if (OnFinished != null)
                OnFinished();
        }
Ejemplo n.º 14
0
        public IEnumerator Run()
        {
            // Check input
            if (name == "")
            { yield break; }

            if (tasks == null || tasks.Length == 0)
            { yield break; }

            if (state == JobStates.Done || state == JobStates.Running)
            { yield break; }

            if (state == JobStates.Failed)
            { Failed(0); yield break; }

            if (state == JobStates.Stopped)
            { Stopped(0); yield break; }

            startTime = DateTime.Now;
            startFrame = Time.frameCount;
            state = JobStates.Running;

            for (curTaskIdx = 0; curTaskIdx < tasks.Length; curTaskIdx++)
            {
                if (state == JobStates.Failed)
                {
                    Failed(curTaskIdx);
                    yield break;
                }

                if (state == JobStates.Stopped)
                {
                    Stopped(curTaskIdx);
                    yield break;
                }
            #if DEBUG
                startTaskTime = DateTime.Now;
                startTaskFrame = Time.frameCount;
            #endif

                if (tasks[curTaskIdx] != null)
                {
                    switch (tasks[curTaskIdx].type)
                    {
                        case Task.TaskType.Action:
                            if (state == JobStates.Failed)
                            {
                                Failed(curTaskIdx);
                                yield break;
                            }
                            else if (state == JobStates.Stopped)
                            {
                                Stopped(curTaskIdx);
                                yield break;
                            }

                            if (tasks[curTaskIdx].action != null)
                            try
                            {
                                tasks[curTaskIdx].action();
                            }
                            catch (Exception ex)
                            {
            #if UNITY_EDITOR
                                Debug.LogError(ex);
            #else
                                Debug.LogWarning("Error Job.Run: " + ex);
            #endif

                                Failed(curTaskIdx);
                                yield break;
                            }
                            yield return null;
                            break;
                        case Task.TaskType.Condition:
                            while (!tasks[curTaskIdx].condition()) //TODO: no endless loop possible?
                            {
                                if (state == JobStates.Failed)
                                {
                                    Failed(curTaskIdx);
                                    yield break;
                                }
                                else if (state == JobStates.Stopped)
                                {
                                    Stopped(curTaskIdx);
                                    yield break;
                                }
                                yield return null;
                            }
                            break;
                        case Task.TaskType.Timer:
                            yield return new WaitForSeconds(tasks[curTaskIdx].time);
                            break;
                        default:
                            break;
                    }
                }

            #if DEBUG
                TimeSpan result = DateTime.Now.Subtract(startTaskTime);
                float duration = (float)result.TotalMilliseconds;
                int frDuration = Time.frameCount - startTaskFrame;
                Debug.LogWarning("Job: " + name + " Task " + curTaskIdx + " finished! Time: " + duration.ToString("f2") + "ms, " + frDuration + " fr");
            #endif
            }

            Finished();
        }
Ejemplo n.º 15
0
 /// <summary>Stops this instance.</summary>
 public void Stop()
 {
     lock (this.stateLock)
     {
         this.State |= JobStates.Cancelling;
     }
     this.cancellationSource.Cancel();
 }
Ejemplo n.º 16
0
        /// <summary>Does the work.</summary>
        public void DoWork()
        {
            this.cancellationSource = new CancellationTokenSource();

            lock (this.stateLock)
            {
                this.State = JobStates.Active;
            }

            try
            {
                this.work(this.cancellationSource.Token);
            }
            catch (OperationCanceledException)
            {
            }
            catch (ThreadAbortException)
            {
            }

            lock (this.stateLock)
            {
                if ((this.State == JobStates.Cancelling) || this.cancellationSource.IsCancellationRequested)
                {
                    this.State = JobStates.Cancelled;
                }
                else
                {
                    this.State = JobStates.Complete;
                }

                if (this.waitHandle != null)
                {
                    this.waitHandle.Set();
                }
            }
        }
Ejemplo n.º 17
0
 public virtual void SetFinished()
 {
     mJobState = JobStates.finished;
 }
Ejemplo n.º 18
0
 public virtual void SetPause()
 {
     mJobState = JobStates.pause;
 }
Ejemplo n.º 19
0
 public virtual void SetProcessing()
 {
     mJobState = JobStates.processing;
 }
Ejemplo n.º 20
0
        public IEnumerator Run()
        {
            // Check input
            if (name == "")
            {
                yield break;
            }

            if (tasks == null || tasks.Length == 0)
            {
                yield break;
            }

            if (state == JobStates.Done || state == JobStates.Running)
            {
                yield break;
            }

            if (state == JobStates.Failed)
            {
                Failed(0); yield break;
            }

            if (state == JobStates.Stopped)
            {
                Stopped(0); yield break;
            }

            startTime  = DateTime.Now;
            startFrame = Time.frameCount;
            state      = JobStates.Running;

            for (curTaskIdx = 0; curTaskIdx < tasks.Length; curTaskIdx++)
            {
                if (state == JobStates.Failed)
                {
                    Failed(curTaskIdx);
                    yield break;
                }

                if (state == JobStates.Stopped)
                {
                    Stopped(curTaskIdx);
                    yield break;
                }
#if DEBUG
                startTaskTime  = DateTime.Now;
                startTaskFrame = Time.frameCount;
#endif

                if (tasks[curTaskIdx] != null)
                {
                    switch (tasks[curTaskIdx].type)
                    {
                    case Task.TaskType.Action:
                        if (state == JobStates.Failed)
                        {
                            Failed(curTaskIdx);
                            yield break;
                        }
                        else if (state == JobStates.Stopped)
                        {
                            Stopped(curTaskIdx);
                            yield break;
                        }

                        if (tasks[curTaskIdx].action != null)
                        {
                            try
                            {
                                tasks[curTaskIdx].action();
                            }
                            catch (Exception ex)
                            {
#if UNITY_EDITOR
                                Debug.LogError(ex);
#else
                                Debug.LogWarning("Error Job.Run: " + ex);
#endif

                                Failed(curTaskIdx);
                                yield break;
                            }
                        }
                        yield return(null);

                        break;

                    case Task.TaskType.Condition:
                        while (!tasks[curTaskIdx].condition())     //TODO: no endless loop possible?
                        {
                            if (state == JobStates.Failed)
                            {
                                Failed(curTaskIdx);
                                yield break;
                            }
                            else if (state == JobStates.Stopped)
                            {
                                Stopped(curTaskIdx);
                                yield break;
                            }
                            yield return(null);
                        }
                        break;

                    case Task.TaskType.Timer:
                        yield return(new WaitForSeconds(tasks[curTaskIdx].time));

                        break;

                    default:
                        break;
                    }
                }

#if DEBUG
                TimeSpan result     = DateTime.Now.Subtract(startTaskTime);
                float    duration   = (float)result.TotalMilliseconds;
                int      frDuration = Time.frameCount - startTaskFrame;
                Debug.LogWarning("Job: " + name + " Task " + curTaskIdx + " finished! Time: " + duration.ToString("f2") + "ms, " + frDuration + " fr");
#endif
            }

            Finished();
        }
Ejemplo n.º 21
0
 public Job(Job job)
 {
     mJobId       = job.JobId;
     mJobState    = job.JobState;
     mJobPriority = job.JobPriority;
 }
Ejemplo n.º 22
0
 public Job(int JobId)
 {
     mJobId       = JobId;
     mJobState    = JobStates.defined;
     mJobPriority = JobPriorities.Normal;
 }
Ejemplo n.º 23
0
        //---------------------------------------------------------------------------------
        // Konstruktoren

        // Der Parameterlose Konstruktor ist Vorraussetzung für die XML- Serialisierung
        public Job()
        {
            mJobState    = JobStates.undefined;
            mJobPriority = JobPriorities.Normal;
        }
Ejemplo n.º 24
0
 public virtual void SetWaiting()
 {
     mJobState = JobStates.waiting;
 }
Ejemplo n.º 25
0
 //Bricht die Bearbeitung eines Jobs ab
 public virtual void SetAborted()
 {
     mJobState = JobStates.aborted;
 }