public WoWHeadParserForm() { InitializeComponent(); RichTextBoxWriter.Instance.OutputBox = consoleBox; _parsers = new List<Type>((int)ParserType.Max); _parserTypes = new List<ParserType>((int)ParserType.Max); _worker = new Worker(WorkerPageDownloaded); }
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(); }
public void StartButtonClick(object sender, EventArgs e) { ParserData.Parser data = m_data.Data[parserBox.SelectedIndex]; PageParser parser = m_parsers[data.ParserType]; parser.Parser = data; parser.Locale = (Locale)localeBox.SelectedItem; parser.Flags = GetSubparsers(); ParsingType type = (ParsingType)parsingControl.SelectedIndex; m_worker = new Worker(type, parser, WorkerPageDownloaded); Worker.ParserValue value = default(Worker.ParserValue); switch (type) { case ParsingType.TypeBySingleValue: { value.Id = (uint)valueBox.Value; break; } case ParsingType.TypeByList: { value.Array = GetEntriesList().Data; numericUpDown.Maximum = progressBar.Maximum = value.Array.Length; break; } case ParsingType.TypeByMultipleValue: { value.Start = (uint)rangeStart.Value; value.End = (uint)rangeEnd.Value; if (value.Start > value.End) { ShowMessageBox(MessageType.MultipleTypeBigger); return; } if (value.Start == value.End) { ShowMessageBox(MessageType.MultipleTypeEqual); return; } numericUpDown.Maximum = progressBar.Maximum = (int)(value.End - value.Start) + 1; break; } case ParsingType.TypeByWoWHeadFilter: { value.Maximum = (data.CountLimit / MaxIdCountPerRequest); numericUpDown.Maximum = progressBar.Maximum = (int)value.Maximum + 1; break; } default: return; } m_worker.SetValue(value); abortButton.Enabled = true; subparsersListBox.Enabled = settingsBox.Enabled = startButton.Enabled = false; numericUpDown.Value = progressBar.Value = 0; SetLabelText(Resources.Label_Working); Requests.Compress = Settings.Default.DataCompression; backgroundWorker.RunWorkerAsync(); }
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); }
public void StartButtonClick(object sender, EventArgs e) { ConstructorInfo cInfo = _parsers[parserBox.SelectedIndex].Value.GetConstructor(new[] { typeof(Locale), typeof(int) }); if (cInfo == null) return; int flags = GetSubparsers(); PageParser parser = (PageParser)cInfo.Invoke(new [] { localeBox.SelectedItem, flags }); if (parser == null) throw new InvalidOperationException("parser"); ParsingType type = (ParsingType)parsingControl.SelectedIndex; _worker = new Worker(type, parser, WorkerPageDownloaded); switch (type) { case ParsingType.TypeBySingleValue: { uint value = (uint)valueBox.Value; _worker.SetValue(value); break; } case ParsingType.TypeByList: { uint[] entries = GetEntriesList(); numericUpDown.Maximum = progressBar.Maximum = entries.Length; _worker.SetValue(entries); break; } case ParsingType.TypeByMultipleValue: { uint startValue = (uint)rangeStart.Value; uint endValue = (uint)rangeEnd.Value; if (startValue > endValue) { ShowMessageBox(MessageType.MultipleTypeBigger); return; } if (startValue == endValue) { ShowMessageBox(MessageType.MultipleTypeEqual); return; } numericUpDown.Maximum = progressBar.Maximum = (int)(endValue - startValue) + 1; _worker.SetValue(startValue, endValue); break; } case ParsingType.TypeByWoWHeadFilter: { int maxValue = (parser.MaxCount / 200); numericUpDown.Maximum = progressBar.Maximum = maxValue + 1; _worker.SetValue((uint)maxValue); break; } default: return; } abortButton.Enabled = true; subparsersListBox.Enabled = settingsBox.Enabled = startButton.Enabled = false; numericUpDown.Value = progressBar.Value = 0; SetLabelText(Resources.Label_Working); Requests.Compress = Settings.Default.DataCompression; backgroundWorker.RunWorkerAsync(); }