示例#1
0
        private async void FormDecklists_Shown(object sender, EventArgs e)
        {
            UpdateUI(true);
            try
            {
                _entry = await _decklists.GetEntryAsync(_deck.DeckName);

                if (_entry == null)
                {
                    SetStatus("This deck does not have an entry in decklists. It will be created.");
                    _entry           = new DecklistsEntry();
                    _entry.Link      = _deck.DeckName;
                    textBoxName.Text = _deck.DeckName;
                }
                else
                {
                    SetStatus("This deck already has an entry in decklists. It will be updated.");
                    textBoxName.Text                 = _entry.Name;
                    textBoxDescription.Text          = _entry.Description;
                    comboBoxStrategy.Text            = _entry.Strategy;
                    checkBoxIncludeColorless.Checked = _entry.Colors.IndexOf(colorlessCode) != -1;
                }
                UpdateUI(false);
            }
            catch (DecklistsException ex)
            {
                ShowError(ex.Message);
                DisableAllExceptCancel();
            }
            catch (WebException)
            {
                ShowError("Network error while accessing Decklists.");
                DisableAllExceptCancel();
            }
        }
示例#2
0
        public async Task Update(DecklistsEntry entry)
        {
            int retries = 5;

            while (retries > 0)
            {
                try
                {
                    await _page.OpenAsync();

                    InsertOrReplaceEntry(entry);
                    await _page.SaveAsync("WikiDeck updated " + entry.Link);

                    retries = 0;
                }
                catch (WikiaEditConflictException)
                {
                    --retries;
                    if (retries == 0)
                    {
                        throw;
                    }
                    await Task.Delay(100);
                }
            }
        }
示例#3
0
        private void InsertOrReplaceEntry(DecklistsEntry entry)
        {
            Match match = Regex.Match(_page.Content, @"{{DecklistRow\s*\|link\s*=\s*" + entry.Link, RegexOptions.Singleline);

            if (match.Success)
            {
                int    startPos = match.Index;
                int    len      = GetEntryLength(_page.Content, startPos);
                string start    = _page.Content.Substring(0, startPos);
                string end      = _page.Content.Substring(startPos + len);
                _page.Content = start + entry.ToString() + end;
            }
            else
            {
                int startPos = _page.Content.IndexOf("<!-- Add your deck info above here! -->");
                if (startPos == -1)
                {
                    throw new DecklistsException("Insertion point not found in decklists.");
                }
                string start = _page.Content.Substring(0, startPos - 1);
                string end   = _page.Content.Substring(startPos);
                _page.Content = start + "\n" + entry.ToString() + "\n" + end;
            }
        }