Click here to Skip to main content
15,892,643 members
Articles / Programming Languages / C#

Dealing with Progressive Operations

Rate me:
Please Sign up or sign in to vote.
4.92/5 (26 votes)
10 May 2010CPOL30 min read 38.4K   319   60  
Through a clean OOP solution to deal with progressive operations, I will implicitly show you how OOP principles can work together to make a full, clean solution.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Erik.Utilities.Interfaces;

namespace Erik.Utilities.Bases
{
    public abstract class BaseProgressiveOperation : IProgressiveOperation
    {
        string _title = "Proccessing";
        string _subtitle = "Please wait";

        protected int _totalSteps;
        protected int _currentStep;

        protected virtual void OnOperationStart(EventArgs e)
        {
            if (OperationStart != null)
                OperationStart(this, e);
        }

        protected virtual void OnOperationProgress(EventArgs e)
        {
            if (OperationProgress != null)
                OperationProgress(this, e);
        }

        protected virtual void OnOperationEnd(EventArgs e)
        {
            if (OperationEnd != null)
                OperationEnd(this, e);
        }

        #region IProgressiveOperation Members

        public event EventHandler OperationStart;

        public event EventHandler OperationProgress;

        public event EventHandler OperationEnd;

        public virtual string MainTitle
        {
            get { return _title; }
            set { _title = value; }
        }

        public virtual string SubTitle
        {
            get { return _subtitle; }
            set { _subtitle = value; }
        }

        public virtual int CurrentProgress
        {
            get
            {
                int ret = 0;

                if (_totalSteps > 0)
                    ret = (100 * _currentStep) / _totalSteps;

                return ret;
            }
        }

        public virtual int TotalSteps
        {
            get { return _totalSteps; }
        }

        public virtual int CurrentStep
        {
            get { return _currentStep; }
        }

        public abstract void Start();

        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead
Spain Spain
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions