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);
}