コード例 #1
0
ファイル: MainForm.cs プロジェクト: bjornreppen/diskfill
        void MakeStateTransition(ComputeState newState)
        {
            switch (newState)
            {
            case ComputeState.Idle:
                buttonCompute.Enabled      = true;
                buttonCompute.Text         = "&Compute";
                numericUpDownSize.Enabled  = true;
                buttonMove.Enabled         = (textBoxResult.Text.Length > 0);
                comboBoxUnits.Enabled      = true;
                numericUpDownLevel.Enabled = true;
                pathBox.Enabled            = true;
                break;

            case ComputeState.Processing:
                buttonCompute.Enabled      = true;
                buttonCompute.Text         = "&Stop";
                buttonMove.Enabled         = false;
                numericUpDownSize.Enabled  = false;
                comboBoxUnits.Enabled      = false;
                numericUpDownLevel.Enabled = false;
                pathBox.Enabled            = false;
                break;

            case ComputeState.Canceled:
                buttonCompute.Enabled = false;
                _computer.Stop();
                break;

            default:
                Debug.Assert(false);
                break;
            }
            _state = newState;
        }
コード例 #2
0
 /// <summary>
 /// Stop running the algorithm and abort its computation,
 /// both synchronously and asychronously.
 /// </summary>
 public override void Abort()
 {
     if (this.mAsyncState == ComputeState.Running)
     {
         this.mAsyncState = ComputeState.Aborting;
     }
     base.Abort();
 }
コード例 #3
0
 /// <summary>
 /// Stop the running algorithm and abort its computation.
 /// </summary>
 public virtual void Abort()
 {
     lock (this.mSyncRoot)
     {
         if (this.mState == ComputeState.Running)
         {
             this.mState = ComputeState.Aborting;
             this.OnStateChanged(ComputeState.Running);
         }
     }
 }
コード例 #4
0
        private void BeginComputation()
        {
            lock (this.mSyncRoot)
            {
                if (this.mState != ComputeState.None)
                {
                    throw new InvalidOperationException();
                }

                this.mState = ComputeState.Running;
                this.OnStarted();
                this.OnStateChanged(ComputeState.None);
            }
        }
コード例 #5
0
        private void SetPieData()
        {
            //
            // check if we are running on the UI thread
            //
            if (this.InvokeRequired == false)
            {
                //
                // see if the process was cancelled
                //
                if (_state == ComputeState.Cancelled)
                {
                    ShowStatus("Ready.");
                }

                _state = ComputeState.Pending;

                //
                // if the user has cancelled the process then we show
                // whatever we have scanned in so far; to guard against
                // showing nothing to the user, we check to see if
                // atleast the name of the root item has been set; if
                // yes, we are good to go!
                //
                if (_data.Root.Name != string.Empty)
                {
                    pnlGView.PieData = _data;
                }

                btnScanNow.Text    = "&Scan Now!";
                btnScanNow.Enabled = true;
            }
            else
            {
                //
                // we aren't on the UI thread so we call ourselves on the UI thread
                //
                SetPieDataDelegate setPieData = new SetPieDataDelegate(SetPieData);
                this.Invoke(setPieData, null);
            }
        }
コード例 #6
0
        /// <summary>
        /// Resets the algorithm to be ready to begin its computation again,
        /// but only if the algorithm isn't currently running or aborting.
        /// </summary>
        public virtual void Reset()
        {
            lock (this.mSyncRoot)
            {
                ComputeState oldState = this.mState;
                switch (this.mState)
                {
                case ComputeState.None:
                    break;

                case ComputeState.Finished:
                case ComputeState.Aborted:
                    this.mState = ComputeState.None;
                    this.OnStateChanged(oldState);
                    break;

                default:
                    throw new InvalidOperationException();
                }
            }
        }
コード例 #7
0
        private void EndComputation()
        {
            lock (this.mSyncRoot)
            {
                ComputeState oldState = this.mState;
                switch (this.mState)
                {
                case ComputeState.Running:
                    this.mState = ComputeState.Finished;
                    this.OnFinished();
                    break;

                case ComputeState.Aborting:
                    this.mState = ComputeState.Aborted;
                    this.OnAborted();
                    break;

                default:
                    throw new InvalidOperationException();
                }
                this.OnStateChanged(oldState);
            }
        }
コード例 #8
0
        private void btnScanNow_Click(object sender, EventArgs e)
        {
            switch (_state)
            {
            case ComputeState.Pending:
                //
                // see that the path is valid
                //
                if ((txtFolderPath.Text == string.Empty) ||
                    !(Directory.Exists(txtFolderPath.Text)))
                {
                    MessageBox.Show("Please specify a valid path to a folder.",
                                    "GView - Error",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    txtFolderPath.Focus();
                    return;
                }

                //
                // update our state
                //
                _state          = ComputeState.Computing;
                btnScanNow.Text = "&Stop";

                //
                // initialize the pie data
                //
                pnlGView.PieData = null;
                _data            = new PieData();
                ComputeSizeDelegate computeSize = new ComputeSizeDelegate(ComputeSize);
                computeSize.BeginInvoke(txtFolderPath.Text,
                                        _data.Root,
                                        new AsyncCallback(OnEndComputeSize),
                                        null);
                break;

            case ComputeState.Computing:
                //
                // update the shared "_state" variable; the worker thread
                // should get notified of this some time in the future
                //
                _state = ComputeState.Cancelled;

                //
                // disable the button till the fact of the process having
                // been cancelled dawns on the worker thread
                //
                btnScanNow.Enabled = false;
                break;

            case ComputeState.Cancelled:
                //
                // we disable the button once we enter this state;
                // so if the user was still able to click it then the
                // system must be on fire or something
                //
                System.Diagnostics.Debug.Assert(false);
                break;
            }
        }
コード例 #9
0
 /// <summary>
 /// Reimplement this function to trigger events and other reactions
 /// to any change the <see cref="State"/> of this
 /// <see cref="AAlgorithm"/> instance which occur after more
 /// specific handlers have been called.</summary>
 /// <param name="oldState">The previous <see cref="State"/> of this
 /// <see cref="AAlgorithm"/> instance before the state change
 /// occurred.</param>
 protected virtual void OnStateChanged(ComputeState oldState)
 {
 }
コード例 #10
0
        /// <summary>
        /// Initializes the layout (if it's just started or has been reset)
        /// and asynchronously runs one iteration, and returns whether it
        /// was able to run the current iteration. Returns false if
        /// <see cref="MaxIterations"/> has been reached, the algorithm has
        /// been aborted, no layout node has moved beyond
        /// <see cref="MovementTolerance"/>, or <see cref="CanIterate()"/>
        /// returns false.</summary>
        /// <param name="forceRestart">Whether to force this algorithm to
        /// start running again if it has finished or has been aborted.</param>
        /// <returns>true if the iteration is successfully run, or false if
        /// the algorithm has finished or has been aborted.</returns>
        public bool AsyncIterate(bool forceRestart)
        {
            if (this.State != ComputeState.None)
            {
                // Can't run asynchronously and synchronously
                // simultaneously
                throw new InvalidOperationException();
            }
            switch (this.mAsyncState)
            {
            case ComputeState.None:
                this.mAsyncState = ComputeState.Running;
                this.OnStarted();
                this.InitializeAlgorithm();
                this.mIter      = 0;
                this.bResetting = false;
                this.bItemMoved = true;
                break;

            case ComputeState.Finished:
            case ComputeState.Aborted:
                if (forceRestart)
                {
                    this.mAsyncState = ComputeState.Running;
                    this.OnStarted();
                    this.InitializeAlgorithm();
                    this.mIter      = 0;
                    this.bResetting = false;
                    this.bItemMoved = true;
                }
                break;
            }
            if (this.mIter < this.mMaxIterations &&
                this.mAsyncState == ComputeState.Running &&
                this.bItemMoved && this.CanIterate())
            {
                if (this.bResetting)
                {
                    this.InitializeAlgorithm();
                    this.mIter      = 0;
                    this.bResetting = false;
                }
                this.SetLastPositions();
                this.PerformPrecalculations();
                if (this.mGraph.NodeCount > 0)
                {
                    this.PerformIteration(this.mIter);
                }
                this.EndIteration(this.mIter);
                this.mIter++;
                return(true);
            }
            else
            {
                switch (this.mAsyncState)
                {
                case ComputeState.Running:
                    this.mAsyncState = ComputeState.Finished;
                    this.OnFinished();
                    break;

                case ComputeState.Aborting:
                    this.mAsyncState = ComputeState.Aborted;
                    this.OnAborted();
                    break;
                }
                return(false);
            }
        }