public LookupChoice Pick(LookupContext lookup)
        {
            Console.WriteLine("Searched for " + lookup.Query);
            PrintResults(lookup.Results);
            string prompt = (lookup.Results.Count == 0) ? "No results found." : "\nPick result number,";
            Console.WriteLine(prompt + " (s)kip or (r)etry");

            string action = Console.In.ReadLine().Trim();
            switch (action)
            {
                case "r":
                    return RetrySearch();
                case "s":
                    return new LookupChoice(LookupChoice.Action.GiveUp);
                default:
                    try
                    {
                        var selected = lookup.Results[Int32.Parse(action)];
                        return new LookupChoice(selected.ImdbId);
                    }
                    catch
                    {
                        Console.WriteLine("Invalid option: s,r, or a number");
                        return Pick(lookup);
                    }
            }
        }
        public SearchResultPickerViewModel(LookupContext lookup)
        {
            LookupResultList = lookup.Results;
            //RaisePropertyChanged("LookupResultList");

            ErrorMessage = lookup.FailureMessage();
            SearchFailed = !String.IsNullOrEmpty(ErrorMessage);
            if(SearchFailed)
            {
                SearchText = lookup.Query;
            }

            QueryTitle = lookup.Query;

            SearchCommand = new RelayCommand(RetrySearch);
            PickSelectedCommand = new RelayCommand(PickSelected);

            SelectedItem = LookupResultList.FirstOrDefault();
        }
Exemple #3
0
 private LookupChoice LookupCalllback(LookupContext lookup)
 {
     return resultPicker.Pick(lookup);
 }
 public LookupChoice Pick(LookupContext lookup)
 {
     LookupResult pick = lookup.Results.FirstOrDefault();
     return (pick != null) ? new LookupChoice(pick) : new LookupChoice(LookupChoice.Action.GiveUp);
 }
        private async Task<LookupChoice> EnqueuePick(LookupContext lookup)
        {
            Task<LookupChoice> task = new Task<LookupChoice>(()=> ShowPicker(lookup),CancellationToken.None, TaskCreationOptions.AttachedToParent);
            queue.Enqueue(task);

            //If task is the only item in queue we need to run it immediately
            TryDequeueNextPick();

            var choice = await task;

            //After dialog closes, continue by attempting to open next picker
            TryDequeueNextPick();

            return choice;
        }
        private LookupChoice ShowPicker(LookupContext lookup)
        {
            SearchResultPicker picker = new SearchResultPicker();
            picker.DataContext = new SearchResultPickerViewModel(lookup);
            picker.Owner = parentWindow;
            picker.ShowDialog();

            isPickerVisible = false;

            if(picker.DialogResult==true)
            {
                return ((SearchResultPickerViewModel)picker.DataContext).LookupChoice;
            }
            else
            {
                return new LookupChoice(LookupChoice.Action.GiveUp);
            }
        }
 public LookupChoice Pick(LookupContext lookup)
 {
     if(uiThread == Thread.CurrentThread)
     {
         throw new ThreadStateException("Pick should be called from another thread");
     }
     var guiTask = EnqueuePick(lookup);
     guiTask.Wait();
     return guiTask.Result;
 }