Exemple #1
0
 public static void ExecuteMethodNTimes(Func <bool> _func, int times)
 {
     for (int i = 0; i < times; i++)
     {
         try
         {
             _func.DynamicInvoke();
             break;
         }
         catch (Exception ex)
         {
             TraceClientExtensions.TraceMessage(System.Diagnostics.TraceEventType.Error, 1,
                                                $"Error al ejecutar {_func.Method.Name}: {ex.ToString()}");
         }
     }
 }
Exemple #2
0
        void ConnectToTeam()
        {
            try
            {
                tries++;
                TraceClientExtensions.TraceMessage(System.Diagnostics.TraceEventType.Information, 1,
                                                   $"Uniendose a equipo {generalData.TeamName} con el usuario {generalData.UserName}");

                using (MyServiceClient c = new MyServiceClient(generalData.ServerIP))
                {
                    string result = c.CreateTeam(generalData.GameName, generalData.TeamName, new string[] { generalData.UserName });
                    if (result != "OK")
                    {
                        if (radRandom.Checked && tries < 2)
                        {
                            generalData.TeamName = generalData.TeamName == radTeam1.Text ? radTeam2.Text : radTeam1.Text;
                            ConnectToTeam();
                        }
                        else
                        {
                            MessageBox.Show("ERROR AL INTENTAR CREAR EL EQUIPO: " + result);
                        }
                    }
                    else
                    {
                        btnOK.Enabled          = false;
                        lblWaitingPlayers.Text = "Esperando al resto de jugadores";
                        CheckTeamsCreated(false);
                    }
                }
            }
            catch (Exception ex)
            {
                TraceClientExtensions.TraceMessage(System.Diagnostics.TraceEventType.Error, 1,
                                                   $"Error al entrar en el equipo {generalData.TeamName} con el usuario {generalData.UserName}: {ex.ToString()}");
                MessageBox.Show("Error al hacer login: " + ex.Message);
            }
        }
Exemple #3
0
 private void btnLogin_Click(object sender, EventArgs e)
 {
     TraceClientExtensions.TraceMessage(TraceEventType.Information, 1, $"Intentando hacer login con el usuario {txtUserName.Text}");
     if (string.IsNullOrEmpty(txtUserName.Text))
     {
         MessageBox.Show("Necesito un nombre de usuario");
     }
     else
     {
         ServerIP = txtServerIP.Text;
         GameName = cmbGameName.Text;
         UserName = txtUserName.Text;
         try
         {
             using (MyServiceClient c = new MyServiceClient(ServerIP))
             {
                 string result = c.Login(UserName, GameName, "");
                 if (result != "OK")
                 {
                     TraceClientExtensions.TraceMessage(TraceEventType.Error, 1,
                                                        $"Error al hacer login con el usuario {txtUserName.Text}: {result}");
                     MessageBox.Show("ERROR AL LOGGUEAR: " + result);
                 }
                 else
                 {
                     grpLogin.Enabled       = false;
                     lblWaitingPlayers.Text = "Esperando al resto de jugadores";
                     LoginFinished?.Invoke(this, EventArgs.Empty);
                 }
             }
         }
         catch (Exception ex)
         {
             TraceClientExtensions.TraceMessage(TraceEventType.Error, 1, $"Error al hacer login con el usuario {txtUserName.Text}: {ex.ToString()}");
             MessageBox.Show("Error al hacer login: " + ex.Message);
         }
     }
 }
Exemple #4
0
        void CheckTeamsCreated(bool onlyCheckOnce)
        {
            try
            {
                TraceClientExtensions.TraceMessage(System.Diagnostics.TraceEventType.Information, 1,
                                                   $"CheckTeamsCreated {generalData.TeamName} con el usuario {generalData.UserName}");

                using (MyServiceClient c = new MyServiceClient(generalData.ServerIP))
                {
                    while (true)
                    {
                        if (IsDisposed || ParentForm.Disposing || ParentForm.IsDisposed)
                        {
                            return;
                        }
                        data = c.GetMusData(generalData.GameName, generalData.TeamName, generalData.UserName);
                        if (data.MusTeams?.Length == 2 &&
                            !string.IsNullOrEmpty(data.MusTeams[0].UserName1) &&
                            !string.IsNullOrEmpty(data.MusTeams[0].UserName2) &&
                            !string.IsNullOrEmpty(data.MusTeams[1].UserName1) &&
                            !string.IsNullOrEmpty(data.MusTeams[1].UserName2))
                        {
                            if (string.IsNullOrEmpty(generalData.TeamName))
                            {
                                if (data.MusTeams[0].UserName1 == generalData.UserName || data.MusTeams[0].UserName2 == generalData.UserName)
                                {
                                    generalData.TeamName = data.MusTeams[0].TeamName;
                                }
                                else
                                {
                                    generalData.TeamName = data.MusTeams[1].TeamName;
                                }
                            }
                            TeamsCreated?.Invoke(this, EventArgs.Empty);
                            break;
                        }
                        else
                        {
                            if (onlyCheckOnce)
                            {
                                if (data.MusTeams?.Length > 0)
                                {
                                    foreach (var t in data.MusTeams)
                                    {
                                        if (t.UserName1 == generalData.UserName || t.UserName2 == generalData.UserName)
                                        {
                                            radTeam1.Checked = t.TeamName == radTeam1.Text ? true : false;
                                            radTeam2.Checked = t.TeamName == radTeam2.Text ? true : false;
                                            break;
                                        }
                                    }
                                }
                                return;
                            }
                            Application.DoEvents();
                            Thread.Sleep(1000);
                            Application.DoEvents();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                TraceClientExtensions.TraceMessage(System.Diagnostics.TraceEventType.Error, 1,
                                                   $"Error al chequear equipos {generalData.TeamName} con el usuario {generalData.UserName}");
                MessageBox.Show("Error al chequear equipos: " + ex.Message);
            }
        }
Exemple #5
0
 public void ChangeDiscards(MusCard[] cards)
 {
     TraceClientExtensions.TraceMessage(System.Diagnostics.TraceEventType.Information, 1, $"Cambiar descartes");
     cardsControl1.ChangeDiscards(cards);
 }
Exemple #6
0
 public void CleanDiscards()
 {
     TraceClientExtensions.TraceMessage(System.Diagnostics.TraceEventType.Information, 1, $"Limpiar descartes");
     cardsControl1.CleanDiscards();
 }