Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

Dealing with Progressive Operations

, 10 May 2010
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)

Share

About the Author

_Erik_
Technical Lead
Spain Spain
No Biography provided

| Advertise | Privacy | Mobile
Web02 | 2.8.140905.1 | Last Updated 10 May 2010
Article Copyright 2010 by _Erik_
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid