This project is read-only.

Get Realm List

Dec 25, 2011 at 9:07 PM
Edited Dec 25, 2011 at 9:12 PM

Here is a simple way to load your realm lists.

I created a class which I called Region;

 

    class Region
    {
        ApiClient Client;

        public string[] LoadRealms(int Region)
        {
            try
            {
                switch (Region)
                {
                    case 0:
                        Client = new ApiClient(WOWSharp.Community.Region.US); //United States
                        break;
                    case 1:
                        Client = new ApiClient(WOWSharp.Community.Region.EU); //Europe
                        break;
                    case 2:
                        Client = new ApiClient(WOWSharp.Community.Region.CN); //China
                        break;
                    case 3:
                        Client = new ApiClient(WOWSharp.Community.Region.KR); //Korea
                        break;
                    case 4:
                        Client = new ApiClient(WOWSharp.Community.Region.TW); //Taiwan
                        break;
                }

                RealmStatusResponse Response;
                Response = Client.GetRealmStatus();

                string[] RealmList = new string[Response.Realms.Count()];

                for (int i = 0; i < Response.Realms.Count(); i++)
                    RealmList[i] = Response.Realms[i].Name;

                return RealmList;
            }
            catch (Exception ee)
            {
                Console.WriteLine(ee.Message);
                return null;
            }
        }
    }

 

I then used a combo box that had each region in it.

When the Index changed the realms combo box would be updated.

 

 

Region reg = new Region();

private void cmbRegion_SelectedIndexChanged(object sender, EventArgs e)
{
     try
     {
          cmbRegion.Enabled = false;
          cmbRealm.Enabled = false;

          string[] Realms = null;
          cmbRealm.Items.Clear();

          Realms = reg.LoadRealms(cmbRegion.SelectedIndex);
                
          if (Realms.Count() == 0)
          {
               MessageBox.Show("An error occured while trying to load realmlist - private void cmdRegion_SelectedIndexChanged.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
               return;
          }

          for (int i = 0; i < Realms.Count(); i++)
               cmbRealm.Items.Add(Realms[i]);

          cmbRealm.SelectedIndex = 0;
          cmbRegion.Enabled = true;
          cmbRealm.Enabled = true;            
     }
     catch (Exception ee) 
     { 
          MessageBox.Show(ee.Message);
          return;
     };
}

 


Simple and effective, may not be best way to do it, but it works.