public void UpdateIpCountry(object o, System.EventArgs e)
		{
			Cambro.Web.Helpers.WriteAlertHeader();

			Cambro.Web.Helpers.WriteAlert("Selecting IpCountry entries...", 1);
			Query q = new Query();
			IpCountrySet bs = new IpCountrySet(q);
			for (int count = 0; count < bs.Count; count++)
			{
				IpCountry c = bs[count];

				try
				{

					Country country = null;
					CountrySet cs = new CountrySet(new Query(new Q(Country.Columns.Code2Letter, c.Code2Letter)));
					if (cs.Count == 1)
						country = cs[0];
					else
					{
						CountrySet cs1 = new CountrySet(new Query(new Q(Country.Columns.Code3Letter, c.Code3Letter)));
						if (cs1.Count == 1)
							country = cs1[0];
					}
					
					if (country != null)
						c.CountryK = country.K;
					else
						c.CountryK = 0;

					c.Update();

					if (count % 10 == 0)
						Cambro.Web.Helpers.WriteAlert("Done " + count + "/" + bs.Count, 2);

				}
				catch(Exception ex)
				{
					Cambro.Web.Helpers.WriteAlert("Exception " + count + "/" + bs.Count + " - " + ex.ToString(), 3);
				}

				bs.Kill(count);

			}
			Cambro.Web.Helpers.WriteAlert("Done!", 3);
			Cambro.Web.Helpers.WriteAlertFooter();
		}
Exemple #2
0
		public static IpCountry Lookup(string ip)
		{
			try
			{
				string[] arr = ip.Split('.');
				Int64 ipInt = (Int64.Parse(arr[0]) * 16777216) + (Int64.Parse(arr[1]) * 65536) + (Int64.Parse(arr[2]) * 256) + Int64.Parse(arr[3]);
				Query q = new Query();
				q.NoLock = true;
				q.QueryCondition = new And(
						new Q(IpCountry.Columns.IpFrom, QueryOperator.LessThanOrEqualTo, ipInt),
						new Q(IpCountry.Columns.IpTo, QueryOperator.GreaterThanOrEqualTo, ipInt)
					);
				q.TopRecords = 1;
				IpCountrySet ipcs = new IpCountrySet(q);
				if (ipcs.Count == 1)
					return ipcs[0];
				else
					return null;
			}
			catch
			{
				return null;
			}
		}