Exemple #1
0
        public void Run()
        {
            Console.WriteLine();
            Console.WriteLine("Duplex client starting...");

            var trace = new TraceSource("Custom", SourceLevels.All);

            trace.Listeners.Add(new AbbreviatedConsoleTraceListener());

            var suffix          = ")";
            var localObj        = new LocalObject();
            var localObservable = Observable
                                  .Interval(TimeSpan.FromSeconds(2))
                                  .Take(2)
                                  .Do(value => trace.TraceInformation("localObservable: {0}", value));

            var client = new QbservableTcpClient <long>(Program.BasicServiceEndPoint, new DuplexLocalEvaluator());

            IQbservable <string> query =
                (from serviceValue in client.Query()
                 let prefix = LocalStaticMethod(localObj.LocalInstanceMethod()) + localObj.LocalInstanceProperty
                              from clientValue in localObservable
                              .Do(value => Console.WriteLine("{0} received value: {1}", Assembly.GetEntryAssembly().EntryPoint.DeclaringType.Namespace, value))
                              from random in LocalIterator()
                              select prefix + clientValue + "/" + serviceValue + ", R=" + random + suffix)
                .Take(21)
                .Do(value => Console.WriteLine("{0} pushing value: {1}", Assembly.GetEntryAssembly().EntryPoint.DeclaringType.Namespace, value));

            using (query.Subscribe(
                       value => ConsoleTrace.WriteLine(ConsoleColor.Green, "Duplex client observed: {0}", value),
                       ex => ConsoleTrace.WriteLine(ConsoleColor.Red, "Duplex client error: {0}", ex.Message),
                       () => ConsoleTrace.WriteLine(ConsoleColor.DarkCyan, "Duplex client completed")))
            {
                Console.WriteLine();
                Console.WriteLine("Duplex client started.  Waiting for basic service notifications...");
                Console.WriteLine();
                Console.WriteLine("(Press any key to stop)");
                Console.WriteLine();

                Console.ReadKey(intercept: true);
            }
        }
Exemple #2
0
        public void Run()
        {
            Console.WriteLine();
            Console.WriteLine("Advanced client starting...");
            Console.WriteLine();

            var suffix               = ")";
            var localObj             = new LocalObject();
            var localTransferableObj = new SharedLibrary.TransferableObject(100);

            var client = new TcpQbservableClient <long>(Program.BasicServiceEndPoint, typeof(SharedLibrary.TransferableObject));

            IQbservable <string> query =
                (from value in client.Query()
                 let r = new TransferableObject(42)
                         let numberBase = new { Remote = r.Value, Local = localTransferableObj.Value }
                 from n in Observable.Range(1, 5)
                 let number = (value + 1) * n
                              where number % 2 == 0
                              let result = numberBase.Remote + numberBase.Local + number
                                           let prefix = LocalStaticMethod(localObj.LocalInstanceMethod()) + localObj.LocalInstanceProperty
                                                        let list = (from i in LocalIterator()
                                                                    select i * 2)
                                                                   .Aggregate("", (acc, cur) => acc + cur + ",", acc => acc.Substring(0, acc.Length - 1))
                                                                   select prefix + result + ", [" + list + "]" + suffix)
                .Take(16)
                .Do(value => Console.WriteLine("{0} pushing value: {1}", Assembly.GetEntryAssembly().EntryPoint.DeclaringType.Namespace, value));

            using (query.Subscribe(
                       value => ConsoleTrace.WriteLine(ConsoleColor.Green, "Advanced client observed: {0}", value),
                       ex => ConsoleTrace.WriteLine(ConsoleColor.Red, "Advanced client error: {0}", ex.Message),
                       () => ConsoleTrace.WriteLine(ConsoleColor.DarkCyan, "Advanced client completed")))
            {
                Console.WriteLine();
                Console.WriteLine("Advanced client started.  Waiting for basic service notifications...");
                Console.WriteLine();
                Console.WriteLine("(Press any key to continue)");
                Console.WriteLine();

                Console.ReadKey(intercept: true);
            }
        }