private void LoadSearchResults()
{
GUIUtils.SetProperty("#Trakt.Items", string.Empty);
GUIBackgroundTask.Instance.ExecuteInBackgroundAndCallback(() =>
{
// People can be null if invoking search from loading parameters
// Internally we set the People to load
if (People == null && !string.IsNullOrEmpty(SearchTerm))
{
// search online
if (!IsMultiPersonSearch)
{
var searchResults = TraktAPI.TraktAPI.SearchPeople(SearchTerm);
if (searchResults != null)
{
People = searchResults.Select(s => s.Person);
}
}
else
{
// do a search for all people in parallel
var threads = new List<Thread>();
foreach (string person in SearchTerm.FromJSON<PersonSearch>().People)
{
var tPersonSearch = new Thread((obj) =>
{
var searchResults = TraktAPI.TraktAPI.SearchPeople(obj as string, 1);
lock (sync)
{
if (searchResults != null)
{
if (People == null)
People = searchResults.Select(s => s.Person);
else
People = People.Union(searchResults.Select(s => s.Person));
}
}
});
tPersonSearch.Start(person);
tPersonSearch.Name = "Search";
threads.Add(tPersonSearch);
}
// wait until all search results are back
threads.ForEach(t => t.Join());
}
}
return People;
},
delegate(bool success, object result)
{
if (success)
{
var people = result as IEnumerable<TraktPersonSummary>;
SendSearchResultsToFacade(people);
}
}, Translation.GettingSearchResults, true);
}