/// <summary> /// Constructor. /// </summary> protected ReadDocumentTask(string file, object caller) : base() { // Set members. _caller = caller; _file = file; // Check state. if (null == _file) { throw new System.ArgumentNullException("Error 1310704890: Given file name is null"); } if (0 == _file.Length) { throw new System.ArgumentException("Error 3052440170: Length of given file name is zero"); } // Make a job. CadKit.Threads.Jobs.Job job = new CadKit.Threads.Jobs.Job(); // Set delegates. job.Start += this._start; job.Finish += this._finish; job.Progress.Minimum = 0; job.Progress.Maximum = this._fileSize(file); // Progress interface. _progress.Value = job.Progress as CadKit.Interfaces.IProgressBar; // Queue the job. CadKit.Threads.Jobs.Manager.Instance.add(job); }
/// <summary> /// See if the job is in the list. /// </summary> public bool Contains(CadKit.Threads.Jobs.Job job) { using (this.Lock.read()) { return(_jobs.Contains(job)); } }
/// <summary> /// Called when the thread starts. /// </summary> protected override void _startJob(CadKit.Threads.Jobs.Job job) { // Should be true. System.Diagnostics.Debug.Assert(false == CadKit.Threads.Tools.MainThread.Instance.IsMainThread); // Make sure there is a document. if (null == this.Document) { return; } // See if the document can insert files. CadKit.Interfaces.IFileInsert insert = this.Document as CadKit.Interfaces.IFileInsert; if (null == insert) { return; } // Feedback. System.Console.WriteLine(System.String.Format("Inserting file '{0}' into '{1}'", this.File, this.Document.Name)); // Insert the file. insert.insert(this.File, this); // The document is now modified. this.Document.Modified = true; }
private void _onAddJob(object sender, System.EventArgs e) { CadKit.Threads.Jobs.Job job = new CadKit.Threads.Jobs.Job(); job.Start += this._threadStart; job.Finish += this._threadFinish; job.Name = System.String.Format("Job {0}", _count++); CadKit.Threads.Jobs.Manager.Instance.add(job); }
/// <summary> /// Called when the job finishes. /// </summary> private void _jobFinish(CadKit.Threads.Jobs.Job job) { lock (this.Mutex) { // Should be true. System.Diagnostics.Debug.Assert(job == _job); } }
/// <summary> /// Constructor /// </summary> public Progress(CadKit.Threads.Jobs.Job job) { if (null == job) { throw new System.ArgumentNullException("Error 3494865470: Null job given", (System.Exception)null); } _job = job; }
/// <summary> /// Remove the job because it is done. Called from the job's thread handler. /// </summary> public void done(CadKit.Threads.Jobs.Job job) { using (this.Lock.write()) { _jobs.Remove(job); } if (null != this.JobFinished) { this.JobFinished(job); } }
/// <summary> /// Clear all the jobs. /// </summary> public void clear() { while (this.NumJobs > 0) { CadKit.Threads.Jobs.Job job = null; using (this.Lock.read()) { job = _jobs[_jobs.Count - 1]; } this.remove(job); } }
/// <summary> /// Called when the reference count goes to zero. /// </summary> protected override void _cleanup() { try { _lock = null; _text = null; _job = null; _notifyDelegate = null; base._cleanup(); } catch (System.Exception e) { System.Console.WriteLine("Error 1615620548: {0}", e.Message); } }
/// <summary> /// Constructor /// </summary> public Job(CadKit.Threads.Jobs.Job job) { if (null == job) { throw new System.ArgumentNullException("Error 4294967295: Null job given", (System.Exception)null); } this.InitializeComponent(); _job = job; _job.Start += this._jobStart; _job.Finish += this._jobFinish; _job.Progress.Notify += this._progressNotify; _label.Text = _job.Name; }
/// <summary> /// Get the mutex. /// </summary> private Job _findRow(CadKit.Threads.Jobs.Job job) { // Should be true. System.Diagnostics.Debug.Assert(false == this.InvokeRequired); ControlList controls = this.ControlsCopy; foreach (System.Windows.Forms.Control control in controls) { CadKit.Threads.GUI.Job row = control as CadKit.Threads.GUI.Job; if (null != row) { if (row.getJob() == job) { return(row); } } } return(null); }
private void _threadStart(CadKit.Threads.Jobs.Job job) { System.TimeSpan rate = job.Progress.UpdateRate; try { int total = 10000000; job.Progress.Minimum = 0; job.Progress.Maximum = total; for (int i = 0; i < total; ++i) { job.Progress.Value = i; } job.Progress.UpdateRate = new System.TimeSpan(0); job.Progress.Value = total; } finally { job.Progress.UpdateRate = rate; } }
/// <summary> /// Add the job. /// </summary> private void _add(CadKit.Threads.Jobs.Job job) { try { if (null == job) { return; } if (true == this.InvokeRequired) { this.BeginInvoke(new VoidReturnJobArgument(this._add), new object[] { job }); } else { // Should already be added to manager. System.Diagnostics.Debug.Assert(true == CadKit.Threads.Jobs.Manager.Instance.Contains(job)); // Make a new job row. CadKit.Threads.GUI.Job row = new CadKit.Threads.GUI.Job(job); // Add it to the control. lock (this.Mutex) { _layout.Controls.Add(row); } // Resize it to fit. this._resizeControl(row); // Repaint. lock (this.Mutex) { _layout.Invalidate(true); _layout.Update(); } } } catch (System.Exception e) { System.Console.WriteLine("Error 2946493990: {0}", e.Message); } }
/// <summary> /// Remove the job. /// </summary> private void _remove(CadKit.Threads.Jobs.Job job) { try { if (null == job) { return; } if (true == this.InvokeRequired) { this.BeginInvoke(new VoidReturnJobArgument(this._remove), new object[] { job }); } else { // Should already be removed from manager. System.Diagnostics.Debug.Assert(false == CadKit.Threads.Jobs.Manager.Instance.Contains(job)); // Find the row. CadKit.Threads.GUI.Job row = this._findRow(job); if (null != row) { lock (this.Mutex) { // Remove the job row. _layout.Controls.Remove(row); _layout.Invalidate(true); _layout.Update(); } } } } catch (System.Exception e) { System.Console.WriteLine("Error 2867827834: {0}", e.Message); } }
/// <summary> /// Called when the thread starts. /// </summary> protected override void _startJob(CadKit.Threads.Jobs.Job job) { // Should be true. System.Diagnostics.Debug.Assert(false == CadKit.Threads.Tools.MainThread.Instance.IsMainThread); // If it exists then bring it forward. CadKit.Interfaces.IDocument idoc = CadKit.Documents.Manager.Instance.findDocument(this.File); if (null != idoc) { CadKit.Documents.Manager.Instance.windowsForward(idoc, this.Caller); return; } // Feedback. System.Console.WriteLine(System.String.Format("Opening file: {0}", this.File)); // Open the document. idoc = CadKit.Documents.Manager.Instance.open(this.File, null, this); // Give the document a command history. Assigning this avoids a dependency. CadKit.Documents.Document doc = idoc as CadKit.Documents.Document; if (null != doc) { doc.CommandHistory = new CadKit.Commands.History(); doc.CommandHistory.add(this.Command); } // Set the delegate. CadKit.Documents.Manager.Instance.setGuiDelegate(idoc, this.Caller); // Create the default user-interface. if (false == this._createDefaultGui(idoc)) { idoc.close(); CadKit.Documents.Manager.Instance.remove(idoc); } }
/// <summary> /// Called when the job progresses. /// </summary> private void _progressNotify(CadKit.Threads.Jobs.Job job) { try { if (true == this.InvokeRequired) { this.BeginInvoke(new ProgessNotifyDelegate(this._progressNotify), new object[] { job }); } else { lock (this.Mutex) { // Should be true. System.Diagnostics.Debug.Assert(job == _job); // Move the progress bar. _progressBar.Minimum = _job.Progress.Minimum; _progressBar.Maximum = _job.Progress.Maximum; _progressBar.Value = _job.Progress.Value; _label.Text = _job.Progress.Text; _label.Width = _label.PreferredWidth; // Was for old layout... //_tableLayout.ColumnStyles[0].Width = _label.PreferredWidth + 20; //_tableLayout.ColumnStyles[1].Width = _tableLayout.Width - (_tableLayout.ColumnStyles[0].Width + _tableLayout.ColumnStyles[2].Width); _tableLayout.Invalidate(true); _tableLayout.Update(); } } } catch (System.Exception e) { System.Console.WriteLine("Error 2088797797: {0}", e.Message); } }
/// <summary> /// Remove a job. /// </summary> public void remove(CadKit.Threads.Jobs.Job job) { if (null == job) { return; } if (false == this.Contains(job)) { return; } using (this.Lock.write()) { _jobs.Remove(job); } job.cancel(); if (null != this.JobRemoved) { this.JobRemoved(job); } }
/// <summary> /// Add a job. /// </summary> public void add(CadKit.Threads.Jobs.Job job) { if (null == job) { return; } if (true == this.Contains(job)) { return; } using (this.Lock.write()) { _jobs.Add(job); } job.queue(); if (null != this.JobAdded) { this.JobAdded(job); } }
/// <summary> /// Called when the thread starts. /// </summary> private void _start(CadKit.Threads.Jobs.Job job) { this._startJob(job); }
/// <summary> /// Called when the thread finishes. /// </summary> private void _finish(CadKit.Threads.Jobs.Job job) { this._finishJob(job); }
/// <summary> /// Start the job. /// </summary> protected virtual void _startJob(CadKit.Threads.Jobs.Job job) { }
/// <summary> /// Finish the job. /// </summary> protected virtual void _finishJob(CadKit.Threads.Jobs.Job job) { }
/// <summary> /// Called when a job finishes. /// </summary> private void _jobFinished(CadKit.Threads.Jobs.Job job) { this._remove(job); }
private void _threadFinish(CadKit.Threads.Jobs.Job job) { }
/// <summary> /// Called when a job is added. /// </summary> private void _jobAdded(CadKit.Threads.Jobs.Job job) { this._add(job); }