public void TestInitialize()
 {
     _service = new CustomSearchService
     {
         Key = "AIzaSyDLsMKnW4JfyHB_y5loy-NTiTi-sCLEQkc",
         CX = "002750746776631512750:q6vczylwrbi"
     };
 }
Beispiel #2
0
        public virtual async Task<Location> GetLocation(string location)
        {
            await Task.Delay(2000);


			char[] arr = location.ToArray ();
			arr = Array.FindAll<char> (arr, (c => (char.IsLetter (c))));
			var location2 = new string(arr).ToLower();
			Location result = null;
			try
			{
            	result = _locations.First(l => l.ImageName.ToLower().Contains(location2));
			}
			catch(InvalidOperationException e)
			{
				Console.WriteLine (e);
			}

			if (result != null)
			{
				return result;
			}
			else
			{
				CustomSearchService google = new CustomSearchService {
					Key = "AIzaSyDLsMKnW4JfyHB_y5loy-NTiTi-sCLEQkc",
					CX = "002750746776631512750:q6vczylwrbi"
				};

				var task = google.GetLocation (location);
				try
				{
					task.Wait ();
				}
				catch(Exception e)
				{
					Console.WriteLine (e);
					return _locations [(new Random ()).Next (0, _locations.Count ())];
				}
				if (task.Result != null && !task.IsFaulted)
				{
					result = task.Result;
					result.Local = false;
					return result;
				}
				else
				{
					return _locations [(new Random ()).Next (0, _locations.Count ())];
				}
			}
        }