示例#1
0
        private void goButton_Click(object sender, EventArgs e)
        {
            IEnumerable <IISOCountry> countries = null;

            switch (typeSelection.SelectedIndex)
            {
            case 0:
                countries = new RipeISOCountryReader().GetDefault();
                break;

            case 1:
                countries = new GeonamesISOCountryReader().GetDefault();
                break;

            case 2:
                countries = new NISOCountries.Wikipedia.HAP.WikipediaISOCountryReader().GetDefault();
                break;

            case 3:
                countries = new NISOCountries.Wikipedia.CSQ.WikipediaISOCountryReader().GetDefault();
                break;
            }
            dataGridView.DataSource = countries.OrderBy(c => c.Alpha2).ToArray();
            dataGridView.AutoResizeColumns();
        }
示例#2
0
        public void RipeISOCountryReader_ParsesFile_Correctly()
        {
            var r = TestUtil.GetTestFileReader();

            var target = new RipeISOCountryReader(r)
                .Parse(@"Test\fixtures\ripe_testfile.txt")
                .ToArray();

            Assert.AreEqual(12, target.Length);
            Assert.AreEqual("NL", target[5].Alpha2);
            Assert.AreEqual("NLD", target[5].Alpha3);
            Assert.AreEqual("528", target[5].Numeric);
            Assert.AreEqual("NETHERLANDS", target[5].CountryName);

            //RIPE has, currently, a newline in the middle of this countryname (and a * at the end). Like this:
            //UNITED KINGDOM OF GREAT BRITAIN AND NORTHERN
            //IRELAND*	 				GB 	GBR 	826
            //Make sure this is "normalized out"
            Assert.AreEqual("UNITED KINGDOM OF GREAT BRITAIN AND NORTHERN IRELAND", target[10].CountryName);
        }
示例#3
0
        public void RipeISOCountryReader_ParsesFile_Correctly()
        {
            var r = TestUtil.GetTestFileReader();

            var target = new RipeISOCountryReader(r)
                         .Parse(@"Test\fixtures\ripe_testfile.txt")
                         .ToArray();

            Assert.AreEqual(12, target.Length);
            Assert.AreEqual("NL", target[5].Alpha2);
            Assert.AreEqual("NLD", target[5].Alpha3);
            Assert.AreEqual("528", target[5].Numeric);
            Assert.AreEqual("NETHERLANDS", target[5].CountryName);

            //RIPE has, currently, a newline in the middle of this countryname (and a * at the end). Like this:
            //UNITED KINGDOM OF GREAT BRITAIN AND NORTHERN
            //IRELAND*	                GB  GBR     826
            //Make sure this is "normalized out"
            Assert.AreEqual("UNITED KINGDOM OF GREAT BRITAIN AND NORTHERN IRELAND", target[10].CountryName);
        }
示例#4
0
        public async Task <IActionResult> AddAgency(AgencyModel addAgencyModel)
        {
            var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value;

            // allow two digit codes, int, and uk
            if (addAgencyModel != null && addAgencyModel.AgencyId != null)
            {
                int index = addAgencyModel.AgencyId.IndexOf(".");
                if (index != 2 && index != 3)
                {
                    ModelState.AddModelError("", "The agency id must start with a 2 character ISO 3166 country code or int, For example: us.agencyname");
                }
                else
                {
                    string code = addAgencyModel.AgencyId.Substring(0, index);
                    if (index == 2 && string.Compare(code.ToLowerInvariant(), "uk") != 0)
                    {
                        string projectRootPath = _hostingEnvironment.ContentRootPath;
                        var    ripeFile        = Path.Combine(projectRootPath, "iso3166-countrycodes.txt");
                        var    isoCountries    = new RipeISOCountryReader().Parse(ripeFile);
                        var    isoLookup       = new ISOCountryLookup <RipeCountry>(isoCountries);

                        var isIsoCode = isoLookup.TryGetByAlpha2(code, out RipeCountry country);
                        if (!isIsoCode)
                        {
                            ModelState.AddModelError("", $"{code} is not a valid country code. The agency id must start with a 2 character ISO 3166 country code or int, For example: us.agencyname");
                        }
                    }
                    else if (index == 3 && string.Compare(code.ToLowerInvariant(), "int") != 0)
                    {
                        ModelState.AddModelError("", "The agency id must start with a 2 character ISO 3166 country code or int, For example: us.agencyname");
                    }
                }
            }

            if (ModelState.IsValid)
            {
                Agency agency = await _context.GetAgency(addAgencyModel.AgencyId);

                if (agency != null)
                {
                    ModelState.AddModelError("", "The agency id already exists, please try again");
                }
                else
                {
                    agency = new Agency()
                    {
                        AgencyId           = addAgencyModel.AgencyId,
                        ApprovalState      = ApprovalState.Requested,
                        Label              = addAgencyModel.Label,
                        CreatorId          = userId,
                        AdminContactId     = userId,
                        TechnicalContactId = userId
                    };
                    agency.AdminContactId = await SelectOrInviteUser(addAgencyModel.AdminContactId, addAgencyModel.AdminContactEmail, addAgencyModel.AgencyId);

                    agency.TechnicalContactId = await SelectOrInviteUser(addAgencyModel.TechnicalContactId, addAgencyModel.TechnicalContactEmail, addAgencyModel.AgencyId);

                    _context.Agencies.Add(agency);
                    await _context.SaveChangesAsync();


                    // Send email.
                    var user = await _context.Users.FindAsync(userId);

                    if (user != null)
                    {
                        try
                        {
                            await SendConfirmationEmail(user, addAgencyModel.AgencyId);
                        }
                        catch (Exception e)
                        {
                        }
                    }

                    var approvers = await _userManager.GetUsersInRoleAsync("admin");

                    foreach (var approver in approvers)
                    {
                        try
                        {
                            await SendApproverEmail(approver, user, addAgencyModel.AgencyId);
                        }
                        catch (Exception e)
                        {
                        }
                    }

                    return(RedirectToAction("Index", "Manage"));
                }
            }

            ViewBag.People = await _context.GetPeopleForUser(userId);

            return(View());
        }