public void AddJob(Job j, JobStates state) { lock (JobsDictLock) { JobStatus js = new JobStatus(); js.State = state; jobs.Add(j, js); } }
public Job(string name) { state = JobStates.Created; // set parameter this.name = name; OnFailed = null; OnFinished = null; OnStopped = null; }
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; }
public Job(string name, Task[] tasks) { state = JobStates.Created; // set parameter this.name = name; this.tasks = tasks; OnFailed = null; OnFinished = null; OnStopped = null; }
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(); } }
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(); } }
/// <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); }
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(); }
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(); }
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(); }
/// <summary>Stops this instance.</summary> public void Stop() { lock (this.stateLock) { this.State |= JobStates.Cancelling; } this.cancellationSource.Cancel(); }
/// <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(); } } }
public virtual void SetFinished() { mJobState = JobStates.finished; }
public virtual void SetPause() { mJobState = JobStates.pause; }
public virtual void SetProcessing() { mJobState = JobStates.processing; }
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(); }
public Job(Job job) { mJobId = job.JobId; mJobState = job.JobState; mJobPriority = job.JobPriority; }
public Job(int JobId) { mJobId = JobId; mJobState = JobStates.defined; mJobPriority = JobPriorities.Normal; }
//--------------------------------------------------------------------------------- // Konstruktoren // Der Parameterlose Konstruktor ist Vorraussetzung für die XML- Serialisierung public Job() { mJobState = JobStates.undefined; mJobPriority = JobPriorities.Normal; }
public virtual void SetWaiting() { mJobState = JobStates.waiting; }
//Bricht die Bearbeitung eines Jobs ab public virtual void SetAborted() { mJobState = JobStates.aborted; }