Inheritance: IHostStub, IStandInProxy
        public void Send_to_standIn()
        {
            var cre = PubnubCredentials.LoadFrom("pubnub credentials.txt");
            using(var sut = new PubnubHostTransceiver(cre, "hostchannel"))
            {
                var standIn = new Pubnub(cre.PublishingKey, cre.SubscriptionKey, cre.SecretKey);
                try
                {
                    var standInChannel = Guid.NewGuid().ToString();

                    var are = new AutoResetEvent(false);
                    ReadOnlyCollection<object> result = null;
                    standIn.subscribe(standInChannel, (ReadOnlyCollection<object> _) =>
                                              {
                                                  result = _;
                                                  are.Set();
                                              });

                    var ho = new HostOutput{CorrelationId = Guid.NewGuid(), Data = "hello".Serialize(), Portname = "portname"};
                    sut.SendToStandIn(new Tuple<string, HostOutput>(standInChannel, ho));

                    Assert.IsTrue(are.WaitOne(5000));

                    var hoReceived = Convert.FromBase64String((string)((JValue)result[0]).Value).Deserialize() as HostOutput;
                    Assert.AreEqual(ho.CorrelationId, hoReceived.CorrelationId);
                    Assert.AreEqual(ho.Data, hoReceived.Data);
                    Assert.AreEqual(ho.Portname, hoReceived.Portname);
                }
                finally
                {
                    standIn.subscribe("standIn", _ => {});
                }
            }
        }
        public void Receive_from_standIn()
        {
            var cre = PubnubCredentials.LoadFrom("pubnub credentials.txt");
            using (var sut = new PubnubHostTransceiver(cre, "hostchannel"))
            {

                var are = new AutoResetEvent(false);
                HostInput result = null;
                sut.ReceivedFromStandIn += _ =>
                                               {
                                                   result = _;
                                                   are.Set();
                                               };

                var standIn = new Pubnub(cre.PublishingKey, cre.SubscriptionKey, cre.SecretKey);
                var hi = new HostInput{CorrelationId = Guid.NewGuid(), Data = "hello".Serialize(), Portname = "portname", StandInEndpointAddress = "endpoint"};
                standIn.publish("hostchannel", hi.Serialize(), _ => { });

                Assert.IsTrue(are.WaitOne(5000));

                Assert.AreEqual(hi.CorrelationId, result.CorrelationId);
                Assert.AreEqual(hi.Data, result.Data);
                Assert.AreEqual(hi.Portname, result.Portname);
                Assert.AreEqual(hi.StandInEndpointAddress, result.StandInEndpointAddress);
            }
        }
Exemplo n.º 3
0
        public void Connect_transceivers()
        {
            var cre = PubnubCredentials.LoadFrom("pubnub credentials.txt");

            using(var host = new PubnubHostTransceiver(cre, "thehost"))
            {
                var config = new FlowRuntimeConfiguration()
                                .AddOperation(new PubnubStandInOperation("op", cre, "thehost"))
                                .AddStream(".in", "op#greeting")
                                .AddStream("op#greeting", ".out");
                using (var fr = new FlowRuntime(config))
                {
                    fr.Message += Console.WriteLine;

                    host.ReceivedFromStandIn += rhi =>
                                                    {
                                                        var data = (string)rhi.Data.Deserialize();
                                                        var ho = new HostOutput
                                                                    {
                                                                        CorrelationId=rhi.CorrelationId,
                                                                        Data =(data + "y").Serialize(),
                                                                        Portname = "greeting"
                                                                    };

                                                        ThreadPool.QueueUserWorkItem(_ =>
                                                        {
                                                            host.SendToStandIn(new Tuple<string, HostOutput>(rhi.StandInEndpointAddress, ho));
                                                        });
                                                    };

                    fr.Process(".in", "hello");

                    var result = "";
                    Assert.IsTrue(fr.WaitForResult(5000, _ => result = _.Data as string));
                    Assert.AreEqual("helloy", result);
                }
            }
        }
 public PubnubOperationHost(IFlowRuntime runtime, PubnubCredentials credentials, string channel)
 {
     var transceiver = new PubnubHostTransceiver(credentials, channel);
     _operationHost = new OperationHost(runtime, transceiver, transceiver);
 }