示例#1
0
        /// <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);
        }
示例#2
0
文件: Manager.cs 项目: perryiv/cadkit
 /// <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));
     }
 }
示例#3
0
        /// <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;
        }
示例#4
0
文件: Form.cs 项目: perryiv/cadkit
 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);
 }
示例#5
0
文件: Job.cs 项目: perryiv/cadkit
 /// <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);
     }
 }
示例#6
0
        /// <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;
        }
示例#7
0
文件: Manager.cs 项目: perryiv/cadkit
 /// <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);
     }
 }
示例#8
0
文件: Manager.cs 项目: perryiv/cadkit
 /// <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);
     }
 }
示例#9
0
 /// <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);
     }
 }
示例#10
0
文件: Job.cs 项目: perryiv/cadkit
        /// <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;
        }
示例#11
0
文件: Jobs.cs 项目: perryiv/cadkit
        /// <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);
        }
示例#12
0
文件: Form.cs 项目: perryiv/cadkit
 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;
     }
 }
示例#13
0
文件: Jobs.cs 项目: perryiv/cadkit
        /// <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);
            }
        }
示例#14
0
文件: Jobs.cs 项目: perryiv/cadkit
        /// <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);
            }
        }
示例#15
0
        /// <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);
            }
        }
示例#16
0
文件: Job.cs 项目: perryiv/cadkit
        /// <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);
            }
        }
示例#17
0
文件: Manager.cs 项目: perryiv/cadkit
        /// <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);
            }
        }
示例#18
0
文件: Manager.cs 项目: perryiv/cadkit
        /// <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);
            }
        }
示例#19
0
 /// <summary>
 /// Called when the thread starts.
 /// </summary>
 private void _start(CadKit.Threads.Jobs.Job job)
 {
     this._startJob(job);
 }
示例#20
0
 /// <summary>
 /// Called when the thread finishes.
 /// </summary>
 private void _finish(CadKit.Threads.Jobs.Job job)
 {
     this._finishJob(job);
 }
示例#21
0
 /// <summary>
 /// Start the job.
 /// </summary>
 protected virtual void _startJob(CadKit.Threads.Jobs.Job job)
 {
 }
示例#22
0
 /// <summary>
 /// Finish the job.
 /// </summary>
 protected virtual void _finishJob(CadKit.Threads.Jobs.Job job)
 {
 }
示例#23
0
文件: Jobs.cs 项目: perryiv/cadkit
 /// <summary>
 /// Called when a job finishes.
 /// </summary>
 private void _jobFinished(CadKit.Threads.Jobs.Job job)
 {
     this._remove(job);
 }
示例#24
0
文件: Form.cs 项目: perryiv/cadkit
 private void _threadFinish(CadKit.Threads.Jobs.Job job)
 {
 }
示例#25
0
文件: Jobs.cs 项目: perryiv/cadkit
 /// <summary>
 /// Called when a job is added.
 /// </summary>
 private void _jobAdded(CadKit.Threads.Jobs.Job job)
 {
     this._add(job);
 }