Debian Codegraph @

external/rx/Rx/NET/Samples/HOL/CS/Excercise8/Step06/Program.cs

raw
1 using System;
2 using System.Linq;
3 using System.Reactive.Linq;
4 using System.Windows.Forms;
5 using System.Reactive.Disposables;
6 using Excercise8.DictionarySuggestService;
7
8 namespace Excercise8
9 {
10 class Program
11 {
12 static void Main()
13 {
14 var txt = new TextBox();
15 var lst = new ListBox { Top = txt.Height + 10 };
16
17 var frm = new Form()
18 {
19 Controls = { txt, lst }
20 };
21
22 var input = (from evt in Observable.FromEventPattern(txt, "TextChanged")
23 select ((TextBox)evt.Sender).Text)
24 .Throttle(TimeSpan.FromSeconds(1))
25 .DistinctUntilChanged()
26 .Do(x => Console.WriteLine(x));
27
28 var svc = new DictServiceSoapClient("DictServiceSoap");
29 var matchInDict = Observable.FromAsyncPattern<string, string, string, DictionaryWord[]>
30 (svc.BeginMatchInDict, svc.EndMatchInDict);
31
32 Func<string, IObservable<DictionaryWord[]>> matchInWordNetByPrefix =
33 term => matchInDict("wn", term, "prefix");
34
35 var res = from term in input
36 from words in matchInWordNetByPrefix(term)
37 select words;
38
39 using (res.Subscribe(words =>
40 {
41 lst.Items.Clear();
42 lst.Items.AddRange((from word in words select word.Word).ToArray());
43 }))
44 {
45 Application.Run(frm);
46 }
47 }
48 }
49 }