예제 #1
0
        public frmLineupAdd()
        {
            InitializeComponent();
            var isoCountry = System.Globalization.RegionInfo.CurrentRegion.ThreeLetterISORegionName;

            var countryResp = SdApi.GetAvailableCountries();

            if (countryResp != null)
            {
                // add the only freeview listing
                _countries.Add(new Country()
                {
                    FullName          = "Great Britain Freeview",
                    PostalCode        = "/",
                    PostalCodeExample = null,
                    ShortName         = "GBR"
                });

                // get all the region/countries
                var regions = new List <string>(countryResp.Keys);
                foreach (var country in regions.Where(region => !region.ToLower().Equals("zzz")).Select(region => countryResp[region]).SelectMany(regionCountries => regionCountries))
                {
                    _countries.Add(country);
                }

                // sort the countries
                _countries = _countries.OrderBy(o => o.FullName).ToList();
                foreach (var country in _countries)
                {
                    cmbCountries.Items.Add(country.FullName);
                }

                // add the DVB satellites
                foreach (var regionCountries in from region in regions where region.ToLower().Equals("zzz") select countryResp[region])
                {
                    _countries.Add(null); cmbCountries.Items.Add(string.Empty);
                    foreach (var country in regionCountries)
                    {
                        _countries.Add(country);
                        cmbCountries.Items.Add(country.FullName);
                    }
                }

                // add a manual option
                _countries.Add(null);
                _countries.Add(new Country()
                {
                    FullName          = "Manual lineup input...",
                    OnePostalCode     = false,
                    PostalCode        = "/[A-Z]+-[A-Z0-9]+-[A-Z0-9]+",
                    PostalCodeExample = "USA-CA00053-DEFAULT",
                    ShortName         = "EPG123"
                });
                cmbCountries.Items.Add(string.Empty); cmbCountries.Items.Add("Manual lineup input...");
            }

            var index = 0;

            for (var i = 0; i < _countries.Count; ++i)
            {
                if (_countries[i] == null)
                {
                    continue;
                }
                if (string.IsNullOrEmpty(_countries[i].ShortName) || !_countries[i].ShortName.ToUpper().Equals(isoCountry))
                {
                    continue;
                }
                index = i;
                break;
            }
            cmbCountries.SelectedIndex = index;

            // automatically fetch the zipcode as entered during TV Setup and perform a fetch
            try
            {
                using (var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Media Center\Settings\ProgramGuide", false))
                {
                    if ((key == null) || (string.IsNullOrEmpty(key.GetValue("strLocation").ToString())))
                    {
                        return;
                    }
                    txtZipcode.Text = key.GetValue("strLocation").ToString().Split(' ')[0];
                    btnFetch_Click(btnFetch, null);
                }
            }
            catch
            {
                // ignored
            }
        }