Skip to content

Instantly share code, notes, and snippets.

@panesofglass
Created May 6, 2011 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save panesofglass/959367 to your computer and use it in GitHub Desktop.
Save panesofglass/959367 to your computer and use it in GitHub Desktop.
using System;
using System.Linq;
using System.Reactive.Linq;
using System.Windows.Forms;
using DictionarySuggest.DictionarySuggestService;
using System.Reactive;
namespace DictionarySuggest
{
class Program
{
static void Main(string[] args)
{
// Input form
var txt = new TextBox();
var lst = new ListBox { Top = txt.Height + 10 };
var frm = new Form { Controls = { txt, lst } };
var input = Observable
.FromEventPattern(txt, "TextChanged")
.Select(evt => ((TextBox)evt.Sender).Text)
.Timestamp()
.Do((Timestamped<string> evt) => Console.WriteLine(evt))
.Select(evt => evt.Value)
.Where(evt => evt.Length > 4)
.DistinctUntilChanged()
.Do(evt => Console.WriteLine(evt));
// Dictionary service
var service = new DictServiceSoapClient("DictServiceSoap");
var matchInDict = Observable.FromAsyncPattern<string, string, string, DictionaryWord[]>
(service.BeginMatchInDict, service.EndMatchInDict);
Func<string, IObservable<DictionaryWord[]>> matchInWordNetByPrefix =
term => matchInDict("wn", term, "prefix")
.Delay(TimeSpan.FromMilliseconds(1 / term.Length * 10000));
var result = from term in input
from words in matchInWordNetByPrefix(term)
.Finally(() => Console.WriteLine("Disposed request for: " + term))
select words;
using (result
.OnErrorResumeNext(Observable.Empty<DictionaryWord[]>())
.ObserveOn(lst)
.Subscribe(words =>
{
lst.Items.Clear();
lst.Items.AddRange(words.Select(word => word.Word).ToArray());
}))
{
Application.Run(frm);
}
}
}
}
@stefanogioli
Copy link

VisualStudio say "Observable.FromAsyncPattern<string, string, string, DictionaryWord[]>
(svc.BeginMatchInDict, svc.EndMatchInDict)" is Obsolete
How could I fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment