Ejemplo n.º 1
0
        private static IDisposable CreateObservableConnectionFluenttly(ChatClient chatClient)
        {
            var subscription =
                chatClient.Connect("guest", "guest")
                .ToObservable()
                .SubscribeConsole();

            return subscription;
        }
Ejemplo n.º 2
0
        private static IDisposable CreateDefferedObservableConnection(ChatClient chatClient)
        {
            var messages = chatClient.ObserveMessagesDeferred("user", "password");
            Console.WriteLine("Press Enter to subscribe to the deffered observable");
            Console.ReadLine();
            var subscription = messages.SubscribeConsole();
            var subscription2 = messages.SubscribeConsole();

            return subscription;
        }
Ejemplo n.º 3
0
        private static IDisposable CreateObservableConnection(ChatClient chatClient)
        {
            var connection = chatClient.Connect("guest", "guest");
            IObservable<string> observableConnection =
                new ObservableConnection(connection);

            var subscription =
                observableConnection.SubscribeConsole("reciever");

            return subscription;
        }
Ejemplo n.º 4
0
        static void MergingObservableConnectionWithLoadedMessages()
        {
            Console.WriteLine();
            Console.WriteLine("----- Merging ObservableConnection with loaded messages ----");

            ChatClient client = new ChatClient();
            IObservable<string> liveMessages = client.ObserveMessages("user", "pass");
            IEnumerable<string> loadedMessages = LoadMessagesFromDB();

            loadedMessages.ToObservable()
                .Concat(liveMessages)
                .SubscribeConsole("merged");

            //this another way to do the same
            liveMessages.
                StartWith(loadedMessages)
                .SubscribeConsole("loaded first");

            client.NotifyRecieved("live message1");
            client.NotifyRecieved("live message2");
        }
Ejemplo n.º 5
0
        public static void Run()
        {
            var chatClient = new ChatClient();
            //var subscription = CreateObservableConnection(chatClient);
            //var subscription = CreateObservableConnectionFluenttly(chatClient);
            var subscription = CreateDefferedObservableConnection(chatClient);

            while (true)
            {
                Console.WriteLine("write a message to be sent, E for error, or X to exit");
                var msg = Console.ReadLine();
                if (msg == "X")
                {
                    chatClient.NotifyClosed();
                    break;
                }
                if (msg == "E")
                {
                    chatClient.NotifyError();
                }

                chatClient.NotifyRecieved(msg);
            }
        }