Ejemplo n.º 1
0
        private void buttonUpdateParticipant_Click(object sender, EventArgs e)
        {
            model.Participant.Status = (string)this.comboBoxCoupleStatus.SelectedValue;

            if (this.model.CompetitionOfficials.Count == 0)
            {
                MessageBox.Show("No officils loaded.");
                return;
            }

            string scoreType = this.checkBoxIncludeScores.Checked ? this.comboBoxScoreType.SelectedItem.ToString() : string.Empty;

            if (this.checkBoxIncludeScoresSingle.Checked)
            {
                ModelFiller.Fill(model.Participant, scoreType, 4, 4, this.model.CompetitionOfficials);
            }

            try
            {
                bool success = apiClient.UpdateCoupleParticipant(model.Participant);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.InnerException.Message);
            }
        }
Ejemplo n.º 2
0
        private void buttonFillWithParticipants_Click(object sender, EventArgs e)
        {
            List <Task> tasks         = new List <Task>();
            Random      random        = new Random();
            int         competitionId = (this.listBoxCompetitions.SelectedItem as CompetitionWrapper).competition.Id;
            int         total         = int.Parse(this.textBoxParticipantCount.Text);
            int         start         = int.Parse(this.textBoxFirstStartNumber.Text);
            int         max           = listBoxCouples.Items.Count - 1;
            List <int>  steps         = new List <int> {
                192, 96, 48, 24, 12, 6, 0
            };
            int maxRounds = 7 - steps.IndexOf(steps.First(s => s < total));

            if (this.model.CompetitionOfficials.Count == 0)
            {
                MessageBox.Show("No officils loaded.");
                return;
            }

            string scoreType = this.checkBoxIncludeScores.Checked ? this.comboBoxScoreType.SelectedItem.ToString() : string.Empty;

            SetProgressBar(this.progressBarParticipants, 0, total);
            for (int i = start; i < start + total; i++)
            {
                tasks.Add(new Task(new Action <object>((state) =>
                {
                    int startNumber      = (int)state;
                    int rank             = startNumber - start + 1;
                    CoupleWrapper couple = listBoxCouples.Items[random.Next(0, max)] as CoupleWrapper;
                    int rounds           = steps.IndexOf(steps.First(s => s < rank)) + 1;

                    var model = new Api.Client.Models.ParticipantCoupleDetail()
                    {
                        CoupleId      = couple.couple.Id,
                        CompetitionId = competitionId,
                        Status        = "Present",
                        StartNumber   = startNumber,
                        Rank          = rank.ToString()
                    };
                    ModelFiller.Fill(model, scoreType, rounds, maxRounds, this.model.CompetitionOfficials);

                    try
                    {
                        Uri participantUrl = apiClient.SaveCoupleParticipant(model);
                        var participant    = apiClient.Get <API_Models.ParticipantCoupleDetail>(participantUrl);
                        lock (this.model.Participants)
                        {
                            this.model.Participants.Add(new ParticipantWrapper(participant));
                        }
                    }
                    catch (Exception ex)
                    {
                        lock (this.model.Participants)
                        {
                            this.model.Participants.Add(new ParticipantWrapper(ex.InnerException, couple.ToString()));
                        }
                    }

                    SetProgressBar(this.progressBarParticipants);
                }), i));
            }

            foreach (var t in tasks)
            {
                t.Start();
            }

            Task.Factory.ContinueWhenAll(tasks.ToArray(), new Action <Task[]>(t =>
            {
                SetProgressBar(this.progressBarParticipants, -1, -1);
                MessageBox.Show("All participants created.");
            }));
        }