public void Run() { var config = new FlowRuntimeConfiguration() .AddEventBasedComponent("Op", new Op()) .AddStream(".receive@op", "op.receive") .AddStream("op.send", ".send@op"); using(var fr = new FlowRuntime(config, new Schedule_for_sync_depthfirst_processing())) { fr.Message += Console.WriteLine; var sut = new HostTranslator(); sut.Translated_input += fr.Process; fr.Result += sut.Process_local_output; Tuple<string, HostOutput> result = null; sut.Translated_output += _ => result = _; var input = new HostInput { CorrelationId = Guid.NewGuid(), Data = "hello".Serialize(), Portname = "op.receive", StandInEndpointAddress = "localhost:1234"}; sut.Process_remote_input(input); Assert.AreEqual("localhost:1234", result.Item1); Assert.AreEqual(input.CorrelationId, result.Item2.CorrelationId); Assert.AreEqual("<hello>".Serialize(), result.Item2.Data); Assert.AreEqual("op.send", result.Item2.Portname); } }
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); } }
public void Process_local_output(IMessage outputMsg) { var corrId = Guid.NewGuid(); var ctx = new FlowContext {Path = outputMsg.Port.Path, StandInOperationName = outputMsg.Port.OperationName, CorrelationId = outputMsg.CorrelationId, Priority = outputMsg.Priority, Causalities = outputMsg.Causalities, FlowStack = outputMsg.FlowStack}; _cache.Add(corrId, ctx); var input = new HostInput {Portname = outputMsg.Port.OutputPortToRemotePortname(), Data = outputMsg.Data.Serialize(), CorrelationId = corrId, StandInEndpointAddress = _standInEndpointAddress}; Translated_output(input); }
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); }
public void Send_to_host() { var cre = PubnubCredentials.LoadFrom("pubnub credentials.txt"); var host = new Pubnub(cre.PublishingKey, cre.SubscriptionKey); try { var are = new AutoResetEvent(false); ReadOnlyCollection<object> result = null; host.subscribe("hostchannel", (ReadOnlyCollection<object> _) => { result = _; are.Set(); }); using (var sut = new PubnubStandInTransceiver(cre, "hostchannel")) { var hi = new HostInput { CorrelationId = Guid.NewGuid(), Data = "hello".Serialize(), Portname = "portname", StandInEndpointAddress = "endpoint" }; sut.SendToHost(hi); Assert.IsTrue(are.WaitOne(5000)); var hiReceived = Convert.FromBase64String((string) ((JValue) result[0]).Value).Deserialize() as HostInput; Assert.AreEqual(hi.CorrelationId, hiReceived.CorrelationId); Assert.AreEqual(hi.Data, hiReceived.Data); Assert.AreEqual(hi.Portname, hiReceived.Portname); Assert.AreEqual(hi.StandInEndpointAddress, hiReceived.StandInEndpointAddress); } } finally { host.unsubscribe("hostchannel", _ => {}); } }
void SendFromStandInToHost(string hostName, HostInput input) { _hosts[hostName].ChannelFromStandIn(input); }
public void SendToHost(HostInput input) { var serializedInput = input.Serialize(); _transceiver.publish(_hostChannel, serializedInput, _ => { }); }
internal void ChannelFromStandIn(HostInput input) { ReceivedFromStandIn(input); }
public void SendToHost(HostInput input) { _channelToHost(_hostName, input); }
public void Process_remote_input(HostInput input) { _cache.Add(input.CorrelationId, input.StandInEndpointAddress); var msg = new Message(input.Portname.StandInPortnameToInputPortname(), input.Data.Deserialize(), input.CorrelationId); Translated_input(msg); }