public static void Main (string[] args) { string fileName = "./allCountries.txt"; Queue<Item> exceptionQueue = new Queue<Item>(); if (args.Length > 0) { fileName = String.Format("./{0}.txt", args[0].ToUpper()); } string awsAccessKey = System.Environment.GetEnvironmentVariable("SDB_ACCESS_KEY"); string awsSecretKey = System.Environment.GetEnvironmentVariable("SDB_SECRET_KEY"); string domainName = "geonames"; // Create a new instance of the SDB class HttpQueryConnection connection = new HttpQueryConnection(awsAccessKey, awsSecretKey, "http://sdb.amazonaws.com"); Sdb sdb = new Sdb(connection); System.Console.WriteLine(); System.Console.WriteLine("Step 1: Creating the domain."); try { sdb.CreateDomain(domainName); } catch (SdbException ex) { handleException(ex); } Domain domain = sdb.GetDomain(domainName); System.Console.WriteLine(); System.Console.WriteLine("Step 2: Loading the GeoNames Data File."); using (StreamReader csvReader = new StreamReader(fileName, Encoding.UTF8, true)) { string inputLine = ""; Console.WriteLine(String.Format("Current Encoding: {0}", csvReader.CurrentEncoding.EncodingName)); while ((inputLine = csvReader.ReadLine()) != null) { string[] inputArray = inputLine.Split(new char[] { '\u0009' }); System.Console.WriteLine(String.Format("Loading Item: {0}, with Place Name: {1}", (string)inputArray.GetValue(0), (string)inputArray.GetValue(1))); System.Console.WriteLine(String.Format("Array Length: {0}", inputArray.Length)); Item item = domain.GetItem((string)inputArray.GetValue(0)); string[] geoNamesTitle = new string[] { "geonamesid", "names", "alternatenames", "latitude", "longitude", "feature_class", "feature_code", "country_code", "cc2", "admin1_code", "admin2_code", "admin3_code", "admin4_code", "population", "elevation", "gtopo30", "timezone", "modification_date" }; string[] geoNames = new string[] { (string)inputArray.GetValue(0), (string)inputArray.GetValue(1), (string)inputArray.GetValue(3), (string)inputArray.GetValue(4), (string)inputArray.GetValue(5), (string)inputArray.GetValue(6), (string)inputArray.GetValue(7), (string)inputArray.GetValue(8), (string)inputArray.GetValue(9), (string)inputArray.GetValue(10), (string)inputArray.GetValue(11), (string)inputArray.GetValue(12), (string)inputArray.GetValue(13), (string)inputArray.GetValue(14), (string)inputArray.GetValue(15), (string)inputArray.GetValue(16), (string)inputArray.GetValue(17), (string)inputArray.GetValue(18) }; IEnumerator attributeArray = geoNames.GetEnumerator(); ArrayList attributes = new ArrayList(); int count = 0; while (attributeArray.MoveNext()) { string current = ((string)attributeArray.Current).Normalize().ToLower(); string title = (string)geoNamesTitle.GetValue(count); if (current.Length > 0) { if (current.Contains(",")) { IEnumerator csvEnumerator = current.Split(new char[] { ',' }).GetEnumerator(); while (csvEnumerator.MoveNext()) { attributes.Add(new Nuxleus.Extension.Aws.Sdb.Attribute(title, (string)csvEnumerator.Current)); } } else { attributes.Add(new Nuxleus.Extension.Aws.Sdb.Attribute(title, current)); } } count++; } try { item.PutAttributes(attributes); } catch (SdbException ex) { exceptionQueue.Enqueue(item); handleException(ex); } } } //IEnumerator queueEnumerator = exceptionQueue.GetEnumerator(); //while (queueEnumerator.MoveNext()) //{ //} }
public static void Main (string[] args) { string awsAccessKey = System.Environment.GetEnvironmentVariable("SDB_ACCESS_KEY"); string awsSecretKey = System.Environment.GetEnvironmentVariable("SDB_SECRET_KEY"); string sample_domain = "sample_domain_1"; string sample_item = "sample_item"; // Create a new instance of the SDB class HttpQueryConnection connection = new HttpQueryConnection(awsAccessKey, awsSecretKey, "http://sdb.amazonaws.com"); Sdb sdb = new Sdb(connection); // Step 1: // Create the domain System.Console.WriteLine(); System.Console.WriteLine("Step 1: Creating the domain."); try { sdb.CreateDomain(sample_domain); } catch (SdbException ex) { handleException(ex); } // Get the sample domain Domain domain = sdb.GetDomain(sample_domain); // Get the sample item Item item = domain.GetItem(sample_item); // Step 2: // Create a series of attributes to associate with the sample eid. ArrayList attributes = new ArrayList(); attributes.Add(new Attribute("name", "value")); attributes.Add(new Attribute("name", "2nd_value")); attributes.Add(new Attribute("name", "3rd_value")); attributes.Add(new Attribute("2nd_name", "4th_value")); attributes.Add(new Attribute("2nd_name", "5th_value")); System.Console.WriteLine(); System.Console.WriteLine("Step 2: Creating initial attributes."); try { item.PutAttributes(attributes); } catch (SdbException ex) { handleException(ex); } // Print out the attributes for the item. printAttributes(item); // Step 3: // Delete the { "name", "3rd_value" } attribute. System.Console.WriteLine(); System.Console.WriteLine("Step 3: Deleting the { \"name\", " + "\"3rd_value\" } attribute."); attributes.Clear(); attributes.Add(new Attribute("name", "3rd_value")); try { item.DeleteAttributes(attributes); } catch (SdbException ex) { handleException(ex); } // Print out the attributes for $item. printAttributes(item); // Step 4: // Delete all attributes with name "2nd_name". System.Console.WriteLine(); System.Console.WriteLine("Step 4: Delete attributes with name " + "\"2nd_name\"."); attributes.Clear(); attributes.Add(new Attribute("2nd_name")); try { item.DeleteAttributes(attributes); } catch (SdbException ex) { handleException(ex); } // Print out the attributes for $item. printAttributes(item); // Step 5: // Replace the value of the "name" attribute of the sample // eID with the value "new_value". System.Console.WriteLine(); System.Console.WriteLine("Step 5: Write value \"new_value\" " + "to the \"name\" attribute."); attributes.Clear(); attributes.Add(new Attribute("name", "new_value")); try { item.PutAttributes(attributes); } catch (SdbException ex) { handleException(ex); } // Print out the attributes for the item. printAttributes(item); // Step 6: // Find all of the eIDs which contain the attribute "name" // with the value "new_value". System.Console.WriteLine(); System.Console.WriteLine("Step 6: Find all eID which contain" + "the attribute { \"name\", " + "\"new_value\" }."); try { QueryResponse queryResponse = domain.Query("[\"name\" = \"new_value\"]"); // Print them out. System.Console.WriteLine(); System.Console.WriteLine("Found items:"); foreach (Item curitem in queryResponse.Items()) { System.Console.WriteLine(curitem.Name); } } catch (SdbException ex) { handleException(ex); } // Step 7: // Delete the sample eID. System.Console.WriteLine(); System.Console.WriteLine("Step 7: Delete the sample item."); try { item.DeleteAttributes(); } catch (SdbException ex) { handleException(ex); } // Print out the attributes for $item. printAttributes(item); // Step 8: // Delete the domain System.Console.WriteLine(); System.Console.WriteLine("Step 8: Deleting the domain."); try { sdb.DeleteDomain(sample_domain); } catch (SdbException ex) { handleException(ex); } System.Console.WriteLine(); }
public static void Main (string[] args) { string awsAccessKey = System.Environment.GetEnvironmentVariable("SDB_ACCESS_KEY"); string awsSecretKey = System.Environment.GetEnvironmentVariable("SDB_SECRET_KEY"); string domainName = "place"; // Create a new instance of the SDB class HttpQueryConnection connection = new HttpQueryConnection(awsAccessKey, awsSecretKey, "http://sdb.amazonaws.com"); Sdb sdb = new Sdb(connection); // Step 1: // Create the domain System.Console.WriteLine(); System.Console.WriteLine("Step 1: Creating the domain."); try { sdb.CreateDomain(domainName); } catch (SdbException ex) { handleException(ex); } Domain domain = sdb.GetDomain(domainName); Dictionary<long, string> countries = new Dictionary<long, string>(); using (StreamReader csvReader = new StreamReader("./hip_countries.csv")) { string inputLine = ""; while ((inputLine = csvReader.ReadLine()) != null) { string[] inputArray = inputLine.Split(new char[] { ',' }); long key = long.Parse((string)inputArray.GetValue(0)); string value = (string)inputArray.GetValue(1); if (!countries.ContainsKey(key)) { countries.Add(key, value); } } } Dictionary<long, long> ipv4_country = new Dictionary<long, long>(); using (StreamReader csvReader = new StreamReader("./hip_ip4_country.csv")) { string inputLine = ""; while ((inputLine = csvReader.ReadLine()) != null) { string[] inputArray = inputLine.Split(new char[] { ',' }); long key = long.Parse((string)inputArray.GetValue(0)); long value = long.Parse((string)inputArray.GetValue(1)); if(!ipv4_country.ContainsKey(key)) { ipv4_country.Add(key, value); } } } //Dictionary<string, string[]> city = new Dictionary<string, string[]>(); using (StreamReader csvReader = new StreamReader("./hip_ip4_city_lat_lng.csv")) { string inputLine = ""; while ((inputLine = csvReader.ReadLine()) != null) { //city.Add((string)inputArray.GetValue(1), new string[] {(string)inputArray.GetValue(0), (string)inputArray.GetValue(2), (string)inputArray.GetValue(3)}); string[] inputArray = inputLine.Split(new char[] { ',' }); string city = (string)inputArray.GetValue(1); string country = ""; string countryCode = ""; long m_country; string m_countryCode; if (ipv4_country.TryGetValue(long.Parse((string)inputArray.GetValue(0)), out m_country)) { country = m_country.ToString(); if (countries.TryGetValue(m_country, out m_countryCode)) { countryCode = m_countryCode.ToString(); } else { countryCode = "unknown"; } } else { country = "unknown"; } string itemName = String.Format("{0}:{1}", city, country); Item item = domain.GetItem(itemName.GetHashCode().ToString()); ArrayList attributes = new ArrayList(); attributes.Add(new Nuxleus.Extension.Aws.Sdb.Attribute("place", (string)inputArray.GetValue(1))); attributes.Add(new Nuxleus.Extension.Aws.Sdb.Attribute("lat", (string)inputArray.GetValue(2))); attributes.Add(new Nuxleus.Extension.Aws.Sdb.Attribute("long", (string)inputArray.GetValue(3))); attributes.Add(new Nuxleus.Extension.Aws.Sdb.Attribute("country", country)); attributes.Add(new Nuxleus.Extension.Aws.Sdb.Attribute("countryCode", countryCode)); try { item.PutAttributes(attributes); } catch (SdbException ex) { handleException(ex); } } } }