public async Task Unsubscribe_throws_exception_when_not_connected()
 {
     var httpPoster   = new Mock <IHttpPost>();
     var bayeuxClient = new BayeuxClient(new HttpLongPollingTransportOptions()
     {
         HttpPost = httpPoster.Object, Uri = "none"
     });
     await bayeuxClient.Unsubscribe("dummy");
 }
示例#2
0
        public static void Main(string[] args)
        {
            log4net.Config.XmlConfigurator.Configure();

            Console.WriteLine("1 - subscribe to channel");
            Console.WriteLine("q - unsubscribe from channel");
            Console.WriteLine("2 - subscribe to channel");
            Console.WriteLine("w - unsubscribe from channel");
            Console.WriteLine("x - exit");
            Console.WriteLine("");
            Console.WriteLine("");

            ServerEndpoint = new Uri(args [0]);

            BayeuxClient client = new BayeuxClient(ServerEndpoint);

            client.DataReceived += (object sender, BayeuxClient.DataReceivedEventArgs e) => {
                if (e.Data.ContainsKey("color"))
                {
                    Console.WriteLine("Received color : " + e.Data ["color"]);
                }
                else if (e.Data.ContainsKey("status"))
                {
                    Console.WriteLine("Received status : " + e.Data ["status"]);
                }
                else
                {
                    Console.WriteLine("Received unknown message");
                }
            };

            client.Subscribe("/devices/51251481d988b43c45000002");
            client.Connect();

            ConsoleKeyInfo key = Console.ReadKey();

            while (key.KeyChar != 'x')
            {
                if (key.KeyChar == '1')
                {
                    client.Subscribe("/devices/51251481d988b43c45000002");
                }

                if (key.KeyChar == 'q')
                {
                    client.Unsubscribe("/devices/51251481d988b43c45000002");
                }

                if (key.KeyChar == '2')
                {
                    client.Subscribe("/devices/512518fcd988b43c45000003");
                }

                if (key.KeyChar == 'w')
                {
                    client.Unsubscribe("/devices/512518fcd988b43c45000003");
                }

                if (key.KeyChar == '*')
                {
                    client.Subscribe("/dees/*");
                }

                if (key.KeyChar == 'i')
                {
                    client.Unsubscribe("/devices/*");
                }

                key = Console.ReadKey();
            }

            client.Disconnect();
            Console.WriteLine("Waiting to disconnect");
            client.WaitFor(BayeuxClient.ClientStateEnum.Disconnected);
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }