npantarhei.distribution.pubnub.transceivers.PubnubHostTransceiver.SendToStandIn C# (CSharp) Method

SendToStandIn() public method

public SendToStandIn ( HostOutput>.Tuple output ) : void
output HostOutput>.Tuple
return void
        public void SendToStandIn(Tuple<string, HostOutput> output)
        {
            Console.WriteLine("sent to standin @ {0}", Thread.CurrentThread.GetHashCode());
            var outputSerialized = output.Item2.Serialize();
            _transceiver.publish(output.Item1, outputSerialized, _ =>
                                                                 {
                                                                     Console.WriteLine("sent");
                                                                 });
        }

Usage Example

        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", _ => {});
                }
            }
        }
All Usage Examples Of npantarhei.distribution.pubnub.transceivers.PubnubHostTransceiver::SendToStandIn