Start() public method

public Start ( ) : void
return void
        private void BackgroundWorkerDoWork(object sender, DoWorkEventArgs e)
        {
            string      locale = (string)localeBox.SelectedItem;
            ParsingType type   = (ParsingType)parsingControl.SelectedIndex;

            _parser = (Parser)Activator.CreateInstance((Type)parserBox.SelectedItem);
            if (_parser == null)
            {
                throw new ArgumentNullException();
            }

            string address = string.Format("http://{0}{1}", (string.IsNullOrEmpty(locale) ? "www." : locale), _parser.Address);

            switch (type)
            {
            case ParsingType.TypeSingle:
            {
                uint value = (uint)valueBox.Value;
                _worker = new Worker(value, address);
                break;
            }

            case ParsingType.TypeList:
            {
                progressBar.Maximum = _entries.Count;

                _worker = new Worker(_entries, address);
                break;
            }

            case ParsingType.TypeMultiple:
            {
                uint startValue = (uint)rangeStart.Value;
                uint endValue   = (uint)rangeEnd.Value;

                if (startValue > endValue)
                {
                    throw new ArgumentOutOfRangeException(@"Starting value can not be bigger than ending value!");
                }

                if (startValue == endValue)
                {
                    throw new ArgumentOutOfRangeException(@"Starting value can not be equal ending value!");
                }

                progressBar.Maximum = (int)(endValue - startValue);

                _worker = new Worker(startValue, endValue, address);
                break;
            }

            default:
                throw new NotImplementedException(string.Format(@"Unsupported type: {0}", type));
            }

            progressLabel.Text = "Downloading...";

            _startTime = DateTime.Now;
            _worker.Start(backgroundWorker);
        }
Exemplo n.º 2
0
        public void StartButtonClick(object sender, EventArgs e)
        {
            int startValue = (int)rangeStart.Value;
            int endValue = (int)rangeEnd.Value;
            int _threadCount = (int)threadCountBox.Value;
            string locale = (string)localeBox.SelectedItem;

            if (parserBox.SelectedItem == null)
                throw new NotImplementedException(@"You should select something first!");

            if (startValue > endValue)
                throw new NotImplementedException(@"Starting value can not be bigger than ending value!");

            if (startValue == endValue)
                throw new NotImplementedException(@"Starting value can not be equal ending value!");

            if (startValue == 1 && endValue == 1)
                throw new NotImplementedException(@"Starting and ending values can not be equal '1'!");

            _parser = (Parser)Activator.CreateInstance((Type)parserBox.SelectedItem);
            if (_parser == null)
                throw new NotImplementedException(@"Parser object is NULL!");

            startButton.Enabled = false;
            stopButton.Enabled = true;
            progressBar.Value = startValue;
            progressBar.Minimum = startValue;
            progressBar.Maximum = endValue;
            progressLabel.Text = "Downloading...";

            string address = string.Format("http://{0}{1}", (string.IsNullOrEmpty(locale) ? "www." : locale), _parser.Address);
            _worker = new Worker(startValue, endValue, _threadCount, address, backgroundWorker);
            _worker.Start();
        }
        public void StartButtonClick(object sender, EventArgs e)
        {
            ParsingType type = (ParsingType)tabControl1.SelectedIndex;
            string locale = (string)localeBox.SelectedItem;

            _parser = (Parser)Activator.CreateInstance((Type)parserBox.SelectedItem);
            if (_parser == null)
                throw new ArgumentNullException(@"Parser");

            string address = string.Format("http://{0}{1}", (string.IsNullOrEmpty(locale) ? "www." : locale), _parser.Address);

            startButton.Enabled = false;
            abortButton.Enabled = true;
            progressBar.Minimum = 0;
            progressBar.Value = 0;

            switch (type)
            {
                case ParsingType.TypeSingle:
                    {
                        int value = (int)valueBox.Value;
                        if (value < 1)
                            throw new ArgumentOutOfRangeException(@"Value", @"Value can not be smaller than '1'!");

                        _worker = new Worker(value, address, backgroundWorker);
                        break;
                    }
                case ParsingType.TypeList:
                    {
                        if (_entries.Count == -1)
                            throw new NotImplementedException(@"Entries list is empty!");

                        progressBar.Visible = true;
                        progressBar.Value = 1;
                        progressBar.Minimum = 1;
                        progressBar.Maximum = _entries.Count;

                        _worker = new Worker(_entries, address, backgroundWorker);
                        break;
                    }
                case ParsingType.TypeMultiple:
                    {
                        int startValue = (int)rangeStart.Value;
                        int endValue = (int)rangeEnd.Value;

                        if (startValue > endValue)
                            throw new ArgumentOutOfRangeException(@"StartValue", @"Starting value can not be bigger than ending value!");

                        if (startValue == endValue)
                            throw new NotImplementedException(@"Starting value can not be equal ending value!");

                        int dif = endValue - startValue;
                        progressBar.Visible = true;
                        progressBar.Value = 0;
                        progressBar.Minimum = 0;
                        progressBar.Maximum = dif;

                        _worker = new Worker(startValue, endValue, address, backgroundWorker);
                        break;
                    }
                default:
                    throw new NotImplementedException(string.Format(@"Unsupported type: {0}", type));
            }

            progressLabel.Text = "Downloading...";
            if (_worker == null)
                throw new ArgumentNullException(@"Worker");

            _startTime = DateTime.Now;
            _worker.Start();
        }
Exemplo n.º 4
0
 private void BackgroundWorkerDoWork(object sender, DoWorkEventArgs e)
 {
     m_worker.Start();
 }
        private void BackgroundWorkerDoWork(object sender, DoWorkEventArgs e)
        {
            string locale = (string)localeBox.SelectedItem;
            ParsingType type = (ParsingType)parsingControl.SelectedIndex;

            _parser = (Parser)Activator.CreateInstance((Type)parserBox.SelectedItem);
            if (_parser == null)
                throw new ArgumentNullException();

            string address = string.Format("http://{0}{1}", (string.IsNullOrEmpty(locale) ? "www." : locale), _parser.Address);

            switch (type)
            {
                case ParsingType.TypeSingle:
                    {
                        uint value = (uint)valueBox.Value;
                        _worker = new Worker(value, address);
                        break;
                    }
                case ParsingType.TypeList:
                    {
                        progressBar.Maximum = _entries.Count;

                        _worker = new Worker(_entries, address);
                        break;
                    }
                case ParsingType.TypeMultiple:
                    {
                        uint startValue = (uint)rangeStart.Value;
                        uint endValue = (uint)rangeEnd.Value;

                        if (startValue > endValue)
                            throw new ArgumentOutOfRangeException(@"Starting value can not be bigger than ending value!");

                        if (startValue == endValue)
                            throw new ArgumentOutOfRangeException(@"Starting value can not be equal ending value!");

                        progressBar.Maximum = (int)(endValue - startValue);

                        _worker = new Worker(startValue, endValue, address);
                        break;
                    }
                default:
                    throw new NotImplementedException(string.Format(@"Unsupported type: {0}", type));
            }

            progressLabel.Text = "Downloading...";

            _startTime = DateTime.Now;
            _worker.Start(backgroundWorker);
        }