Program.cs 1.4 KB

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