Ejemplo n.º 1
0
        public IEnumerable <string> Get(string searchLocation)
        {
            Flickr flickr     = new Flickr(Properties.Settings.Default.flickrKey);
            var    searchTerm = searchLocation;
            var    options    = new PhotoSearchOptions {
                Tags = searchTerm
            };
            PhotoCollection photos    = flickr.PhotosSearch(options);
            List <string>   locations = new List <string>();

            using (locationsEntities1 context = new locationsEntities1())
            {
                try
                {
                    foreach (Photo photo in photos)
                    {
                        locations.Add(photo.LargeUrl);
                        var locationsSearched = new SearchedLocation();
                        locationsSearched.location = photo.Title;
                        locationsSearched.title    = photo.Title;
                        locationsSearched.imageUrl = photo.Medium640Url;
                        locationsSearched.weburl   = photo.WebUrl;

                        context.SearchedLocations.Add(locationsSearched);
                        context.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception();
                }
            }
            return(locations);
        }
Ejemplo n.º 2
0
        internal static IEnumerable <SearchedLocation> ExamineToSearchedLocations(ISearchResults SearchResults)
        {
            var returnList = new List <SearchedLocation>();

            // check that there are any search results
            if (SearchResults.TotalItemCount > 0)
            {
                // iterate through the search results
                foreach (SearchResult result in SearchResults)
                {
                    var sl = new SearchedLocation();
                    sl.ExamineNodeId = result.Id;
                    sl.SearchScore   = result.Score;

                    var location = new IndexedLocation();
                    location.IndexNodeId      = result.Id;
                    location.Key              = result.Fields.ContainsKey("Key") ? new Guid(result.Fields["Key"]) : Guid.Empty;
                    location.Name             = result.Fields.ContainsKey("Name") ? result.Fields["Name"] : string.Empty;
                    location.LocationTypeKey  = result.Fields.ContainsKey("LocationTypeKey") ? new Guid(result.Fields["LocationTypeKey"]) : Guid.Empty;
                    location.LocationTypeName = result.Fields.ContainsKey("LocationTypeName") ? result.Fields["LocationTypeName"] : string.Empty;
                    location.Latitude         = result.Fields.ContainsKey("Latitude") ? System.Convert.ToDouble(result.Fields["Latitude"]) : 0;
                    location.Longitude        = result.Fields.ContainsKey("Longitude") ? System.Convert.ToDouble(result.Fields["Longitude"]) : 0;
                    location.Address1         = result.Fields.ContainsKey("Address1") ? result.Fields["Address1"] : string.Empty;
                    location.Address2         = result.Fields.ContainsKey("Address2") ? result.Fields["Address2"] : string.Empty;
                    location.Locality         = result.Fields.ContainsKey("Locality") ? result.Fields["Locality"] : string.Empty;
                    location.Region           = result.Fields.ContainsKey("Region") ? result.Fields["Region"] : string.Empty;
                    location.PostalCode       = result.Fields.ContainsKey("PostalCode") ? result.Fields["PostalCode"] : string.Empty;
                    location.CountryCode      = result.Fields.ContainsKey("CountryCode") ? result.Fields["CountryCode"] : string.Empty;
                    location.Email            = result.Fields.ContainsKey("Email") ? result.Fields["Email"] : string.Empty;
                    location.Phone            = result.Fields.ContainsKey("Phone") ? result.Fields["Phone"] : string.Empty;

                    //Handle Custom properties
                    List <IndexedPropertyData> customProps;

                    if (result.Fields.ContainsKey("CustomPropertyData"))
                    {
                        customProps = ExamineCustomPropsToIndexedProps(result.Fields["CustomPropertyData"]);
                    }
                    else
                    {
                        customProps = new List <IndexedPropertyData>();
                    }

                    location.CustomPropertyData = customProps;

                    //Add all properties to Dictionary
                    location.AllPropertiesDictionary = AllPropertiesToDictionary(result.Fields, customProps);

                    // add the location to SL
                    sl.IndexedLocation = location;

                    //add to list
                    returnList.Add(sl);
                }
            }

            return(returnList);
        }