public void Receive_from_host()
        {
            var cre = PubnubCredentials.LoadFrom("pubnub credentials.txt");

            using (var sut = new PubnubStandInTransceiver(cre, "hostchannel"))
            {
                var are = new AutoResetEvent(false);
                HostOutput result = null;
                sut.ReceivedFromHost += _ =>
                                            {
                                                result = _;
                                                are.Set();
                                            };

                var sender = new Pubnub(cre.PublishingKey, cre.SubscriptionKey);
                var ho = new HostOutput {CorrelationId = Guid.NewGuid(), Data = "hello".Serialize(), Portname = "portname"};
                sender.publish(sut.StandInEndpointAddress, ho.Serialize(), _ => { });

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

                Assert.AreEqual(ho.CorrelationId, result.CorrelationId);
                Assert.AreEqual(ho.Data, result.Data);
                Assert.AreEqual(ho.Portname, result.Portname);
            }
        }
        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", _ => {});
                }
            }
        }
            void ProcessOnHost(HostInput input, Action<HostOutput> sendOutput)
            {
                Assert.AreEqual("localhost:1234", input.StandInEndpointAddress);

                var inputPort = new Port(input.Portname); // remoteOp.inputPort
                var outputPortname = string.Format(inputPort.OperationName + "." + inputPort.Name + "-out"); // remoteOp.outputPort
                var output = new HostOutput { CorrelationId = input.CorrelationId, Data = ("<" + input.Data.Deserialize() + ">").Serialize(), Portname = outputPortname};
                sendOutput(output);
            }
예제 #4
0
        public void Process_remote_input(HostOutput output)
        {
            var ctx = _cache.Get(output.CorrelationId);

            var port = output.Portname.RemotePortnameToInputPort(ctx.Path, ctx.StandInOperationName);
            var inputMsg = new ContextualizedMessage(port, output.Data.Deserialize(), ctx.CorrelationId)
                                                     {Priority = ctx.Priority,
                                                      Causalities = ctx.Causalities,
                                                      FlowStack = ctx.FlowStack};
            Translated_input(inputMsg);
        }
예제 #5
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);
                }
            }
        }
예제 #6
0
 void SendFromHostToStandIn(string standInName, HostOutput output)
 {
     _standIns[standInName].ChannelFromHost(output);
 }
 internal void ChannelFromHost(HostOutput output)
 {
     ReceivedFromHost(output);
 }
예제 #8
0
 public void Process_local_output(IMessage message)
 {
     var standInEndpointAddress = _cache.Get(message.CorrelationId);
     var output = new HostOutput { Portname = message.Port.OutputPortToStandInPortname(), Data = message.Data.Serialize(), CorrelationId = message.CorrelationId};
     Translated_output(new Tuple<string, HostOutput>(standInEndpointAddress, output));
 }