Esempio n. 1
0
        public static void Run()
        {
            var svc = new DictServiceSoapClient("DictServiceSoap");

//            svc.BeginMatchInDict("wn", "react", "prefix",
//                iar => {
//                    var words = svc.EndMatchInDict(iar);
//                    foreach (var word in words)
//                        Console.WriteLine(word.Word);
//                },
//                null);

//            var matchInDict = Observable.FromAsyncPattern<string, string, string, DictionaryWord[]>(svc.BeginMatchInDict, svc.EndMatchInDict);


//            Func<string, IObservable<DictionaryWord[]>> suggestionForPrefix = prefix => matchInDict("wn", prefix, "prefix");
            Func <string, IObservable <DictionaryWord[]> > suggestionForPrefix = prefix => Observable.Return(new[] { new DictionaryWord()
                                                                                                                     {
                                                                                                                         Word = "test"
                                                                                                                     } });

            var input = "reactive";

            for (int len = 4; len <= input.Length; len++)
            {
                var term = input.Substring(0, len);
                suggestionForPrefix(term).Subscribe(
                    words => Console.WriteLine(term + " -> " + words.Length + " => " + string.Join(";", from w in words select w.Word)));
            }


            Console.ReadLine();
        }
Esempio n. 2
0
        public static void ReactiveDictionarySuggestSevice()
        {
            var svc = new DictServiceSoapClient("DictServiceSoap");

            //Converting the above fragment to Rx isn't very hard, using the FromAnsycPattern method
            //which takes a whole bunch of generic overloads for various Begin* method param counts.
            //The generic params passed to this bridge are the types of the Begin* method params,
            //as well as the return type of End*.

            Func<string, string, string, IObservable<DictionaryWord[]>> matchInDict = Observable.FromAsyncPattern
                <string, string, string, DictionaryWord[]>(
                    svc.BeginMatchInDict,
                    svc.EndMatchInDict
                );

            //The result of this bridging is a Func delegate thats takes the web service params and
            //produces and observable sequence that will receive the result.

            IObservable<DictionaryWord[]> resultsFromDictSvc = matchInDict("wn", "react", "prefix");
            IDisposable subscription = resultsFromDictSvc.Subscribe(
                words =>
                    {
                        foreach (DictionaryWord word in words)
                        {
                            Console.WriteLine(word.Word);
                        }
                    });

            Console.ReadLine(); //Wait to allow user to see output.

            subscription.Dispose(); //Unsubscribe (could just use a using block)
        }
Esempio n. 3
0
        static void Main()
        {
            var svc         = new DictServiceSoapClient("DictServiceSoap");
            var matchInDict = Observable.FromAsyncPattern <string, string, string, DictionaryWord[]>
                                  (svc.BeginMatchInDict, svc.EndMatchInDict);

            Func <string, IObservable <DictionaryWord[]> > matchInWordNetByPrefix =
                term => matchInDict("wn", term, "prefix");

            var res          = matchInWordNetByPrefix("react");
            var subscription = res.Subscribe(
                words =>
            {
                foreach (var word in words)
                {
                    Console.WriteLine(word.Word);
                }
            },
                ex =>
            {
                Console.Error.WriteLine(ex.Message);
            }
                );

            Console.ReadLine();
        }
Esempio n. 4
0
        public static void NonReactiveDictionarySuggestSevice()
        {
            var svc = new DictServiceSoapClient("DictServiceSoap");

            //Starts a webservice call
            svc.BeginMatchInDict("wn", "react", "prefix",
                                 //AsyncCallback delegate
                                 iar =>
                                     {
                                         DictionaryWord[] words = svc.EndMatchInDict(iar);
                                         foreach (DictionaryWord word in words)
                                         {
                                             Console.WriteLine(word.Word);
                                         }
                                     },
                                 null
                );

            //The above operation is quite "clumsy",
            //composition with our other Async data sources (TextBox) becomes difficult.
            //It is also not clear how one can cancel existing requests,
            //such that the Callback procedure is guaranteed not to be called anymore.
            //The data aspect of the Async call not being immediately apparent.

            Console.ReadLine(); //Wait to allow user to see output.
        }
Esempio n. 5
0
        static void Main()
        {
            var txt = new TextBox();
            var lst = new ListBox {
                Top = txt.Height + 10
            };

            var frm = new Form()
            {
                Controls = { txt, lst }
            };

            var input = (from evt in Observable.FromEventPattern(txt, "TextChanged")
                         select((TextBox)evt.Sender).Text)
                        .Throttle(TimeSpan.FromSeconds(1))
                        .DistinctUntilChanged()
                        .Do(x => Console.WriteLine(x));

            var svc         = new DictServiceSoapClient("DictServiceSoap");
            var matchInDict = Observable.FromAsyncPattern <string, string, string, DictionaryWord[]>
                                  (svc.BeginMatchInDict, svc.EndMatchInDict);

            Func <string, IObservable <DictionaryWord[]> > matchInWordNetByPrefix =
                term => matchInDict("wn", term, "prefix");

            using (input.Subscribe(inp => Console.WriteLine("User wrote: " + inp)))
            {
                Application.Run(frm);
            }
        }
Esempio n. 6
0
        static void Main()
        {
            var svc = new DictServiceSoapClient("DictServiceSoap");
            var matchInDict = Observable.FromAsyncPattern<string, string, string, DictionaryWord[]>
                (svc.BeginMatchInDict, svc.EndMatchInDict);

            Func<string, IObservable<DictionaryWord[]>> matchInWordNetByPrefix =
                term => matchInDict("wn", term, "prefix");

            var res = matchInWordNetByPrefix("react");
            var subscription = res.Subscribe(
                words =>
                {
                    foreach (var word in words)
                        Console.WriteLine(word.Word);
                },
                ex =>
                {
                    Console.Error.WriteLine(ex.Message);
                }
            );

            Console.ReadLine();

        }
Esempio n. 7
0
        static void Main()
        {
            var txt = new TextBox();
            var lst = new ListBox { Top = txt.Height + 10 };

            var frm = new Form()
            {
                Controls = { txt, lst }
            };

            var input = (from evt in Observable.FromEventPattern(txt, "TextChanged")
                         select ((TextBox)evt.Sender).Text)
                         .Throttle(TimeSpan.FromSeconds(1))
                         .DistinctUntilChanged()
                         .Do(x => Console.WriteLine(x));

            var svc = new DictServiceSoapClient("DictServiceSoap");
            var matchInDict = Observable.FromAsyncPattern<string, string, string, DictionaryWord[]>
                (svc.BeginMatchInDict, svc.EndMatchInDict);

            Func<string, IObservable<DictionaryWord[]>> matchInWordNetByPrefix =
                term => matchInDict("wn", term, "prefix");

            var res = from term in input
                      from words in matchInWordNetByPrefix(term)
                      select words;

            using (input.Subscribe(inp => Console.WriteLine("User wrote: " + inp)))
            {
                Application.Run(frm);
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Get the word definition from a web service, internet connection is
        /// needed
        /// </summary>
        public void GetMeaning()
        {
            DictServiceSoapClient dictionary     = new DictServiceSoapClient("DictServiceSoap");
            WordDefinition        wordDefinition = dictionary.Define(this.Value);

            this.Meaning = wordDefinition.Definitions;
        }
Esempio n. 9
0
        public static void Run()
        {
            // The Web Service
            var svc         = new DictServiceSoapClient("DictServiceSoap");
            var matchInDict = Observable.FromAsyncPattern <string, string, string, DictionaryWord[]>(svc.BeginMatchInDict, svc.EndMatchInDict);
            Func <string, IObservable <DictionaryWord[]> > suggestionForPrefix = prefix => matchInDict("wn", prefix, "prefix");

            // The GUI
            var textBox = new TextBox();
            var listBox = new ListBox {
                Top = textBox.Height + 10
            };
            var form = new Form {
                Controls = { textBox, listBox }
            };

            var input = (from evt in Observable.FromEvent <EventArgs>(textBox, "TextChanged")
                         select((TextBox)evt.Sender).Text)
                        .Where(w => w.Length > 3)
                        .Throttle(TimeSpan.FromSeconds(1))
                        .Do(x => Console.WriteLine("After Throttle:" + x));

            #region Stubbing

            const string INPUT = "reactive";
            var          rand  = new Random();

            IObservable <string> test_input = Observable.GenerateWithTime(
                3,
                len => len <= INPUT.Length,
                len => len + 1,
                len => INPUT.Substring(0, len),
                _ => TimeSpan.FromMilliseconds(rand.Next(200, 1200))
                )
                                              .ObserveOn(textBox)
                                              .Do(term => textBox.Text = term)
                                              .Throttle(TimeSpan.FromSeconds(1));

            Func <string, IObservable <DictionaryWord[]> > test_suggestionForPrefix = term => Observable.Return(
                (from i in Enumerable.Range(0, rand.Next(0, 50))
                 select new DictionaryWord {
                Word = term + i
            }).ToArray())
                                                                                      .Delay(TimeSpan.FromSeconds(rand.Next(1, 10)));
            #endregion

            // replace with test_ to use the stubbed observables
            var suggestions = from term in input
                              from words in suggestionForPrefix(term).TakeUntil(input)
                              select words;

            using (suggestions.ObserveOn(listBox).Subscribe(words =>
            {
                listBox.Items.Clear();
                listBox.Items.AddRange((from word in words select word.Word).ToArray());
            },
                                                            ex => Console.WriteLine(ex)))
                Application.Run(form);
        }
 public void define(string options)
 {
     System.Diagnostics.Debug.WriteLine("We are here");
     string word = JsonHelper.Deserialize<string[]>(options)[0];
     DictServiceSoapClient serviceClient = new DictServiceSoapClient();
     serviceClient.DefineCompleted += new EventHandler<DefineCompletedEventArgs>(getMeanings);
     serviceClient.DefineAsync(word);
 }
        public void define(string options)
        {
            System.Diagnostics.Debug.WriteLine("We are here");
            string word = JsonHelper.Deserialize <string[]>(options)[0];
            DictServiceSoapClient serviceClient = new DictServiceSoapClient();

            serviceClient.DefineCompleted += new EventHandler <DefineCompletedEventArgs>(getMeanings);
            serviceClient.DefineAsync(word);
        }
Esempio n. 12
0
        static void Main()
        {
            var txt = new TextBox();
            var lst = new ListBox {
                Top = txt.Height + 10
            };

            var frm = new Form()
            {
                Controls = { txt, lst }
            };

#if PRODUCTION
            // Turn the user input into a tamed sequence of strings.
            var textChanged = from evt in Observable.FromEventPattern(txt, "TextChanged")
                              select((TextBox)evt.Sender).Text;

            var input = textChanged
                        .Throttle(TimeSpan.FromSeconds(1))
                        .DistinctUntilChanged();
#else
            // Test input
            var input = (from len in Enumerable.Range(3, 8)
                         select "reactive".Substring(0, len)) // rea, reac, react, reacti, reactiv, reactive
                        .ToObservable();
#endif

            // Bridge with the web service's MatchInDict method.
            var svc         = new DictServiceSoapClient("DictServiceSoap");
            var matchInDict = Observable.FromAsyncPattern <string, string, string, DictionaryWord[]>
                                  (svc.BeginMatchInDict, svc.EndMatchInDict);

            Func <string, IObservable <DictionaryWord[]> > matchInWordNetByPrefix =
                term => matchInDict("wn", term, "prefix");

            // The grand composition connecting the user input with the web service.
            var res = (from term in input
                       select matchInWordNetByPrefix(term))
                      .Switch();

            // Synchronize with the UI thread and populate the ListBox or signal an error.
            using (res.ObserveOn(lst).Subscribe(
                       words =>
            {
                lst.Items.Clear();
                lst.Items.AddRange((from word in words select word.Word).ToArray());
            },
                       ex =>
            {
                MessageBox.Show(
                    "An error occurred: " + ex.Message, frm.Text, MessageBoxButtons.OK, MessageBoxIcon.Error
                    );
            }))
            {
                Application.Run(frm);
            } // Proper disposal happens upon exiting the application.
        }
Esempio n. 13
0
        static void Main()
        {
            var txt = new TextBox();
            var lst = new ListBox { Top = txt.Height + 10 };

            var frm = new Form()
            {
                Controls = { txt, lst }
            };

#if PRODUCTION
            // Turn the user input into a tamed sequence of strings.
            var textChanged = from evt in Observable.FromEventPattern(txt, "TextChanged")
                              select ((TextBox)evt.Sender).Text;
                       
            var input = textChanged
                        .Throttle(TimeSpan.FromSeconds(1))
                        .DistinctUntilChanged();
#else
            // Test input
            var input = (from len in Enumerable.Range(3, 8)
                         select "reactive".Substring(0, len)) // rea, reac, react, reacti, reactiv, reactive
                         .ToObservable();
#endif

            // Bridge with the web service's MatchInDict method.
            var svc = new DictServiceSoapClient("DictServiceSoap");
            var matchInDict = Observable.FromAsyncPattern<string, string, string, DictionaryWord[]>
                (svc.BeginMatchInDict, svc.EndMatchInDict);

            Func<string, IObservable<DictionaryWord[]>> matchInWordNetByPrefix =
                term => matchInDict("wn", term, "prefix");

            // The grand composition connecting the user input with the web service.
            var res = (from term in input
                      select matchInWordNetByPrefix(term))
                      .Switch();

            // Synchronize with the UI thread and populate the ListBox or signal an error.
            using (res.ObserveOn(lst).Subscribe(
                words =>
                {
                    lst.Items.Clear();
                    lst.Items.AddRange((from word in words select word.Word).ToArray());
                },
                ex =>
                {
                    MessageBox.Show(
                        "An error occurred: " + ex.Message, frm.Text, MessageBoxButtons.OK, MessageBoxIcon.Error
                    );
                }))
            {
                Application.Run(frm);
            } // Proper disposal happens upon exiting the application.
        }
Esempio n. 14
0
        public static void Run()
        {
            // The Web Service
            var svc = new DictServiceSoapClient("DictServiceSoap");
            var matchInDict = Observable.FromAsyncPattern<string, string, string, DictionaryWord[]>(svc.BeginMatchInDict, svc.EndMatchInDict);
            Func<string, IObservable<DictionaryWord[]>> suggestionForPrefix = prefix => matchInDict("wn", prefix, "prefix");

            // The GUI
            var textBox = new TextBox();
            var listBox = new ListBox {Top = textBox.Height + 10};
            var form = new Form {Controls = {textBox, listBox}};

            var input = (from evt in Observable.FromEvent<EventArgs>(textBox, "TextChanged")
                         select ((TextBox) evt.Sender).Text)
                .Where(w => w.Length > 3)
                .Throttle(TimeSpan.FromSeconds(1))
                .Do(x => Console.WriteLine("After Throttle:" + x));

            #region Stubbing

            const string INPUT = "reactive";
            var rand = new Random();

            IObservable<string> test_input = Observable.GenerateWithTime(
                    3,
                    len => len <= INPUT.Length,
                    len => len + 1,
                    len => INPUT.Substring(0, len),
                    _ => TimeSpan.FromMilliseconds(rand.Next(200, 1200))
                )
               .ObserveOn(textBox)
               .Do(term => textBox.Text = term)
               .Throttle(TimeSpan.FromSeconds(1));

                Func<string, IObservable<DictionaryWord[]>> test_suggestionForPrefix = term => Observable.Return(
                                                        (from i in Enumerable.Range(0, rand.Next(0, 50))
                                                            select new DictionaryWord { Word = term + i }).ToArray())
                                                            .Delay(TimeSpan.FromSeconds(rand.Next(1, 10)));
            #endregion

            // replace with test_ to use the stubbed observables
            var suggestions = from term in input
                             from words in suggestionForPrefix(term).TakeUntil(input)
                             select words;

            using (suggestions.ObserveOn(listBox).Subscribe(words =>
                                          {
                                              listBox.Items.Clear();
                                              listBox.Items.AddRange((from word in words select word.Word).ToArray());
                                          },
                                          ex => Console.WriteLine(ex)))
                Application.Run(form);
        }
Esempio n. 15
0
        static void Main(string[] args)
        {
            var service = new DictServiceSoapClient("DictServiceSoap");
            var match   = Observable
                          .FromAsyncPattern <string, string, string, DictionaryWord[]>(
                service.BeginMatchInDict, service.EndMatchInDict);

            Func <string, IObservable <DictionaryWord[]> > matchInWordNetByPrefix = term => match("wn", term, "prefix");

            TextBox t1 = new TextBox();
            Form    f1 = new Form
            {
                Controls = { t1 }
            };


            var textSource = Observable
                             .FromEventPattern <EventArgs>(t1, "TextChanged")
                             .Throttle(TimeSpan.FromMilliseconds(250))
                             .Select(x => (x.Sender as TextBox).Text)
                             .Where(x => x.Length > 0)
                             .DistinctUntilChanged();

            var result = matchInWordNetByPrefix("react");

            var formRequest = textSource
                              .Subscribe(x =>
            {
                var servicequestion = matchInWordNetByPrefix(x)
                                      .Subscribe(words =>
                {
                    Console.WriteLine("{0} - {1}", x, words.Count());
                    foreach (var w in words)
                    {
                        Console.Write("{0},", w.Word);
                    }
                    Console.WriteLine("\n*******************************************");
                },
                                                 ex =>
                {
                    Console.WriteLine("\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
                    Console.WriteLine(ex.Message);
                    Console.WriteLine("\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
                });
            });


            using (formRequest)
            {
                Application.Run(f1);
            }
        }
Esempio n. 16
0
        static void Main(string[] args)
        {
            var t1 = new TextBox();
            var l1 = new ListBox {
                Top = t1.Height + 10, Height = 250, Width = 150
            };
            var f1 = new Form
            {
                Controls = { t1, l1 }
            };

            var textSource = Observable
                             .FromEventPattern <EventArgs>(t1, "TextChanged")
                             .Throttle(TimeSpan.FromMilliseconds(50))
                             .Select(x => (x.Sender as TextBox).Text)
                             .Where(x => x.Length >= 3)
                             .DistinctUntilChanged()
                             .Do(Console.WriteLine);

            var service    = new DictServiceSoapClient("DictServiceSoap");
            var dictSource = Observable
                             .FromAsyncPattern <string, string, string, DictionaryWord[]>(service.BeginMatchInDict, service.EndMatchInDict);

            Func <string, IObservable <DictionaryWord[]> > matchInWordNetByPrefix = term => dictSource("wn", term, "prefix");


            //var res = from term in textSource
            //          from words in matchInWordNetByPrefix(term)
            //                          .Finally(() => Console.WriteLine("Disposed request for: " + term))
            //                          .TakeUntil(textSource)
            //          select words;

            var res = (from term in textSource
                       select matchInWordNetByPrefix(term))
                      .Switch();


            using (res
                   .ObserveOn(WindowsFormsSynchronizationContext.Current)
                   .Subscribe(w =>
            {
                l1.Items.Clear();
                l1.Items.AddRange(w.Select(word => word.Word).ToArray());
            },
                              ex =>
            {
                MessageBox.Show(ex.Message);
            }))

                Application.Run(f1);
        }
Esempio n. 17
0
        static void Main()
        {
            var svc = new DictServiceSoapClient("DictServiceSoap");
            var matchInDict = Observable.FromAsyncPattern<string, string, string, DictionaryWord[]>
                (svc.BeginMatchInDict, svc.EndMatchInDict);
            
            var res = matchInDict("wn", "react", "prefix");
            var subscription = res.Subscribe(words =>
            {
                foreach (var word in words)
                    Console.WriteLine(word.Word);
            });

            Console.ReadLine();

        }
Esempio n. 18
0
        static void Main()
        {
            var svc = new DictServiceSoapClient("DictServiceSoap");
            svc.BeginMatchInDict("wn", "react", "prefix",
                iar =>
                {
                    var words = svc.EndMatchInDict(iar);
                    foreach (var word in words)
                        Console.WriteLine(word.Word);
                },
                null
            );

            Console.ReadLine();

        }
Esempio n. 19
0
        void old()
        {
            var svc = new DictServiceSoapClient("DictServiceSoap");

            svc.BeginMatchInDict("wn", "react", "prefix",
                                 iar =>
            {
                var words = svc.EndMatchInDict(iar);
                foreach (var w in words)
                {
                    Console.WriteLine(w.Word);
                }
            }, null);

            Console.ReadLine();
        }
Esempio n. 20
0
        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)
                         .TakeUntil(input)
                         .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);
        }
Esempio n. 21
0
        static void Main()
        {
            var txt = new TextBox();
            var lst = new ListBox {
                Top = txt.Height + 10
            };

            var frm = new Form()
            {
                Controls = { txt, lst }
            };

            var input = (from evt in Observable.FromEventPattern(txt, "TextChanged")
                         select((TextBox)evt.Sender).Text)
                        .Where(term => term.Length >= 3)
                        //.Throttle(TimeSpan.FromSeconds(1))
                        .DistinctUntilChanged()
                        .Do(Console.WriteLine);

            var svc         = new DictServiceSoapClient("DictServiceSoap");
            var matchInDict = Observable.FromAsyncPattern <string, string, string, DictionaryWord[]>
                                  (svc.BeginMatchInDict, svc.EndMatchInDict);

            Func <string, IObservable <DictionaryWord[]> > matchInWordNetByPrefix =
                term => matchInDict("wn", term, "prefix");

            var res = from term in input
                      from words in matchInWordNetByPrefix(term)
                      select words;

            using (res.ObserveOn(lst).Subscribe(
                       words =>
            {
                lst.Items.Clear();
                lst.Items.AddRange((from word in words select word.Word).ToArray());
            },
                       ex =>
            {
                MessageBox.Show(
                    "An error occurred: " + ex.Message, frm.Text, MessageBoxButtons.OK, MessageBoxIcon.Error
                    );
            }))
            {
                Application.Run(frm);
            }
        }
Esempio n. 22
0
        static void Main()
        {
            var svc         = new DictServiceSoapClient("DictServiceSoap");
            var matchInDict = Observable.FromAsyncPattern <string, string, string, DictionaryWord[]>
                                  (svc.BeginMatchInDict, svc.EndMatchInDict);

            var res          = matchInDict("wn", "react", "prefix");
            var subscription = res.Subscribe(words =>
            {
                foreach (var word in words)
                {
                    Console.WriteLine(word.Word);
                }
            });

            Console.ReadLine();
        }
Esempio n. 23
0
        static void Main()
        {
            var txt = new TextBox();
            var lst = new ListBox { Top = txt.Height + 10 };

            var frm = new Form()
            {
                Controls = { txt, lst }
            };

            var input = (from evt in Observable.FromEventPattern(txt, "TextChanged")
                         select ((TextBox)evt.Sender).Text)
                         .Where(term => term.Length >= 3)
                         //.Throttle(TimeSpan.FromSeconds(1))
                         .DistinctUntilChanged()
                         .Do(Console.WriteLine);

            var svc = new DictServiceSoapClient("DictServiceSoap");
            var matchInDict = Observable.FromAsyncPattern<string, string, string, DictionaryWord[]>
                (svc.BeginMatchInDict, svc.EndMatchInDict);

            Func<string, IObservable<DictionaryWord[]>> matchInWordNetByPrefix =
                term => matchInDict("wn", term, "prefix");

            var res = from term in input
                      from words in matchInWordNetByPrefix(term)
                      select words;

            using (res.ObserveOn(lst).Subscribe(
                words =>
                {
                    lst.Items.Clear();
                    lst.Items.AddRange((from word in words select word.Word).ToArray());
                },
                ex =>
                {
                    MessageBox.Show(
                        "An error occurred: " + ex.Message, frm.Text, MessageBoxButtons.OK, MessageBoxIcon.Error
                    );
                }))
            {
                Application.Run(frm);
            }
        }
Esempio n. 24
0
 private void searchFor(string text, int retries = 0)
 {
     string[] words;
     try
     {
         var serv = new DictServiceSoapClient();
         write($"Getting words for {text}");
         var task = serv.MatchInDictAsync("wn", text, "prefix");
         Task.WaitAny(task, Task.Delay(TimeSpan.FromMilliseconds(600)));
         if (task.IsCompleted)
         {
             var wordItems = task.Result;
             words = wordItems.Select(wi => wi.Word).ToArray();
         }
         else
         {
             words = new[] { "Timeout getting words" };
         }
         write($"Done for {text}");
     }
     catch (CommunicationException ex) when(ex.InnerException == null)
     {
         words = new[] { $"Communication error: {ex.Message}" };
     }
     catch (AggregateException ex)
     {
         words = ex.InnerExceptions.Select(ex_ => $"Aggregate errors: {ex_.Message}").ToArray();
     }
     catch (CommunicationException ex) when(ex.InnerException != null)
     {
         if (retries < 3)
         {
             searchFor(text, retries + 1);
             return;
         }
         words = new[] { $"Communication error w{ex.InnerException.Message}" };
     }
     catch (Exception ex)
     {
         words = new[] { $"Unexpected exception: {ex.Message}" };
     }
     Dispatcher.Invoke(() => LboxWords.ItemsSource = words);
 }
Esempio n. 25
0
        static void Main()
        {
            var svc = new DictServiceSoapClient("DictServiceSoap");
            var matchInDict = Observable.FromAsyncPattern<string, string, string, DictionaryWord[]>
                (svc.BeginMatchInDict, svc.EndMatchInDict);

            Func<string, IObservable<DictionaryWord[]>> matchInWordNetByPrefix =
                term => matchInDict("wn", term, "prefix");

            var input = "reactive";
            for (int len = 3; len <= input.Length; len++)
            {
                var req = input.Substring(0, len);
                matchInWordNetByPrefix(req).Subscribe(
                    words => Console.WriteLine(req + " --> " + words.Length)
                );
            }

            Console.ReadLine();
        }
Esempio n. 26
0
        static void Main()
        {
            var svc         = new DictServiceSoapClient("DictServiceSoap");
            var matchInDict = Observable.FromAsyncPattern <string, string, string, DictionaryWord[]>
                                  (svc.BeginMatchInDict, svc.EndMatchInDict);

            Func <string, IObservable <DictionaryWord[]> > matchInWordNetByPrefix =
                term => matchInDict("wn", term, "prefix");

            var input = "reactive";

            for (int len = 3; len <= input.Length; len++)
            {
                var req = input.Substring(0, len);
                matchInWordNetByPrefix(req).Subscribe(
                    words => Console.WriteLine(req + " --> " + words.Length)
                    );
            }

            Console.ReadLine();
        }
 public FindDefinitionQueryHandler(string endpointConfigurationName)
 {
     dictServiceClient = new DictServiceSoapClient(endpointConfigurationName);
     dictServiceClient.Open();
 }
Esempio n. 28
0
 public DictServiceSoapClient() :
     base(DictServiceSoapClient.GetDefaultBinding(), DictServiceSoapClient.GetDefaultEndpointAddress())
 {
     this.Endpoint.Name = EndpointConfiguration.DictServiceSoap.ToString();
     ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
 }
Esempio n. 29
0
 private static System.ServiceModel.Channels.Binding GetDefaultBinding()
 {
     return(DictServiceSoapClient.GetBindingForEndpoint(EndpointConfiguration.DictServiceSoap));
 }
Esempio n. 30
0
 private static System.ServiceModel.EndpointAddress GetDefaultEndpointAddress()
 {
     return(DictServiceSoapClient.GetEndpointAddress(EndpointConfiguration.DictServiceSoap));
 }
Esempio n. 31
0
        public static void SearchDictionaryAsyncFromUserThrottledAndDistinctInputThenUpdateUIWithCancellationSwitch()
        {
            //Set up UI with a TextBox Input and ListBox for results
            var txt = new TextBox();
            var list = new ListBox
            {
                Top = txt.Height + 10,
                Height = 250,
                Width = 290
            };
            var frm = new Form
            {
                Controls = { txt, list }
            };

            //Create an instance of our Async WebService Proxy
            var svc = new DictServiceSoapClient("DictServiceSoap");

            //Turn user input into a teamed sequence of strings
            IObservable<string> textChanged = Observable.FromEvent<EventArgs>(txt, "TextChanged")
                .Select(evt => ((TextBox)evt.Sender).Text);

            //Create an observable for input from the user
            IObservable<string> input = textChanged
                .DistinctUntilChanged()
                .Throttle(TimeSpan.FromSeconds(1))
                .Do(Console.WriteLine);

            //Wrap the Begin End Async Method Pattern for Dictionary web service
            Func<string, string, string, IObservable<DictionaryWord[]>> matchInDict =
                Observable.FromAsyncPattern<string, string, string, DictionaryWord[]>(
                    svc.BeginMatchInDict,
                    svc.EndMatchInDict
                    );

            //This is an alternative composition which does nto leverage SelectMany for the projection
            //We use Switch() which cancel's out one's existing subscriptions and hops to a new one upon new input.
            // ---o-----o--------------o
            //    |     |              |
            //    V     |              |                         |
            //====---o--X---..         |                         S
            //    =  |  |              |                         W
            //    =  V  V              |                         I
            //    ===O  ----o------o---X--..                     T
            //       =      |      |   |                         C
            //       =      V      V   V                         T
            //       =======O======O   ---o----o----o--..        |
            //                     =      |    |    |            V
            //                     =      V    V    V
            //                     =======O====O====O=== IObservable<T>

            IObservable<DictionaryWord[]> resultFromDictSvc = (from term in input
                                                               select matchInDict("wn", term, "prefix"))
                                                               .Switch();

            //Synchronize with the UI thread and populate the ListBox or signal an Error
            using (resultFromDictSvc.ObserveOn(list).Subscribe(
                dictionaryWords =>
                {
                    list.Items.Clear();

                    list.Items.AddRange((dictionaryWords
                                            .Select(dictionaryWord => dictionaryWord.Word))
                                            .ToArray());
                },
                ex => MessageBox.Show(String.Format("An error occurred: {0}", ex.Message), frm.Text)))
            {
                Application.Run(frm);
            } //Proper disposal happens upon exiting the application
        }
Esempio n. 32
0
        public static void SearchDictionaryAsyncFromUserThrottledAndDistinctInputThenUpdateUI()
        {
            //Set up UI with a TextBox Input and ListBox for results
            var txt = new TextBox();
            var list = new ListBox
            {
                Top = txt.Height + 10,
                Height = 250,
                Width = 290
            };
            var frm = new Form
            {
                Controls = { txt, list }
            };

            //Create an instance of our Async WebService Proxy
            var svc = new DictServiceSoapClient("DictServiceSoap");

            //Turn user input into a teamed sequence of strings
            IObservable<string> textChanged = Observable.FromEvent<EventArgs>(txt, "TextChanged")
                .Select(evt => ((TextBox)evt.Sender).Text);

            //Create an observable for input from the user
            IObservable<string> input = textChanged
                .DistinctUntilChanged()
                .Throttle(TimeSpan.FromSeconds(1))
                .Do(Console.WriteLine);

            //Wrap the Begin End Async Method Pattern for Dictionary web service
            Func<string, string, string, IObservable<DictionaryWord[]>> matchInDict =
                Observable.FromAsyncPattern<string, string, string, DictionaryWord[]>(
                    svc.BeginMatchInDict,
                    svc.EndMatchInDict
                    );

            //Create an observable for result of Async Dictionary web service call
            //The grand composition connecting the user input with the web service
            IObservable<DictionaryWord[]> resultFromDictSvc = input.SelectMany(
                term => matchInDict("wn", term, "prefix")
                );

            //Synchronize with the UI thread and populate the ListBox or signal an Error
            using (resultFromDictSvc.ObserveOn(list).Subscribe(
                dictionaryWords =>
                {
                    list.Items.Clear();

                    list.Items.AddRange((dictionaryWords
                                            .Select(dictionaryWord => dictionaryWord.Word))
                                            .ToArray());
                },
                ex => MessageBox.Show(String.Format("An error occurred: {0}", ex.Message), frm.Text)))
            {
                Application.Run(frm);
            } //Proper disposal happens upon exiting the application
        }
Esempio n. 33
0
        public Dict()
        {
            _client = new DictServiceSoapClient();

        }
Esempio n. 34
0
 public MatchQueryProvider(DictServiceSoapClient client)
 {
     _client = client;
 }
 public DictServiceSoapClient(EndpointConfiguration endpointConfiguration, System.ServiceModel.EndpointAddress remoteAddress) :
     base(DictServiceSoapClient.GetBindingForEndpoint(endpointConfiguration), remoteAddress)
 {
     this.Endpoint.Name = endpointConfiguration.ToString();
     ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
 }
 public DictServiceSoapClient(EndpointConfiguration endpointConfiguration) :
     base(DictServiceSoapClient.GetBindingForEndpoint(endpointConfiguration), DictServiceSoapClient.GetEndpointAddress(endpointConfiguration))
 {
     this.Endpoint.Name = endpointConfiguration.ToString();
     ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
 }