public override void Execute() { Packet p = _keyPort.Receive(); if (p != null) { _key = p.Content?.ToString() ?? _key; Drop(p); _keyPort.Close(); } p = _inPort.Receive(); if (p != null) { if (p.Type == Packet.Types.Normal && p.Attributes.ContainsKey(_key)) { _valPort.Send(Create(p.Attributes[_key])); } if (_outPort.IsConnected()) { _outPort.Send(p); } else { Drop(p); } } }
public override void Execute() { Packet p = _pathPort.Receive(); if (p != null) { var pathToFile = p.Content?.ToString(); Drop(p); try { if (_writer != null) { _writer.Close(); } if (pathToFile == null) { FlowError.Complain("FileWriterText(" + Name + ").PATH has received null path."); } Directory.CreateDirectory(Path.GetDirectoryName(pathToFile)); _writer = new StreamWriter(pathToFile); System.Console.WriteLine("Opened file " + pathToFile + " for writing."); } catch (System.Exception e) { FlowError.Complain("FileWriterText(" + Name + ").PATH received IP threw exception: " + e.Message); } } p = _inPort.Receive(); if (p != null) { if (p.Content != null) { _writer.WriteLine(p.Content); _writer.Flush(); } if (_outPort.IsConnected()) { _outPort.Send(p); } else { Drop(p); } } }
public override void Execute() { Packet p = _capPort.Receive(); if (p != null) { _cap = p.Content as Model.IEnvInstance <ST, ST>; Drop(p); } // we need a capability before to continue if (_cap == null) { return; } p = _envPort.Receive(); if (p != null) { if (p.Content is Model.Env <ST> env) { //var j = JObject.Parse(env.Rest.Value); //Console.WriteLine("RunEnvModel: run customId: " + j["customId"].ToString()); try { var res = _cap.Run(env).Result; _outPort.Send(Create(res)); } catch (System.Exception e) { if (_errPort.IsConnected()) { var errp = Create(env); errp.Attributes.Add("exception", e); _errPort.Send(errp); } else { Console.WriteLine("RunEnvModel: System.Exception: " + e.Message); } } } Drop(p); } }
public override void Execute() { var p = _inPort.Receive(); if (p != null) { if (p.Content is bool b) { if (_truePort.IsConnected()) { if (b) { _truePort.Send(p); } else { _truePort.Close(); } } else if (_falsePort.IsConnected()) { if (!b) { _falsePort.Send(p); } else { _falsePort.Close(); } } else { Drop(p); } } else { Drop(p); FlowError.Complain("Expected IP to be a boolean value. Got: " + p.Content.GetType()); } } }
public override void Execute() /*throws Throwable*/ { Packet p; while ((p = _inport.Receive()) != null) { string line = p.Content as string; LongWaitStart(_timeout); //Thread.Sleep(3000); // testing only if (p.Type == Packet.Types.Open) { Console.Out.WriteLine("==> Open Bracket"); } else if (p.Type == Packet.Types.Close) { Console.Out.WriteLine("==> Close Bracket"); } else if (p.Content == null) { Console.Out.WriteLine("null"); } else { Console.Out.WriteLine(p.Content); } //} LongWaitEnd(); if (_outport.IsConnected()) { _outport.Send(p); } else { Drop(p); } } }
public override void Execute() /*throws Throwable*/ { Packet wp = _destination.Receive(); if (wp == null) { FlowError.Complain("Destination not specified: " + Name); } _destination.Close(); Packet fp = _flush.Receive(); if (fp != null) { Drop(fp); } _flush.Close(); Packet p = _cfgp.Receive(); if (p != null) { string param = p.Content.ToString(); _timeout = Double.Parse(param); Drop(p); _cfgp.Close(); } Object dest = wp.Content; TextWriter tw; if (dest is TextWriter) { tw = dest as TextWriter; } else if (dest is string) { tw = new StreamWriter(dest as string); } else if (dest is Stream) { tw = new StreamWriter(dest as Stream); } else { tw = new StringWriter(); } Drop(wp); while ((p = _inport.Receive()) != null) { //using (TimeoutHandler t = new TimeoutHandler(_timeout, this)) //{ LongWaitStart(_timeout); //Thread.Sleep(3000); // testing only if (p.Type == Packet.Types.Open) { tw.WriteLine("==> Open Bracket"); } else if (p.Type == Packet.Types.Close) { tw.WriteLine("==> Close Bracket"); } else if (p.Content == null) { tw.WriteLine("null"); } else { tw.WriteLine(p.Content); } //} LongWaitEnd(); // sw.Write(linesep); if (fp != null) { string s = (string)fp.Content; if (!(s.Equals("-"))) { tw.Flush(); } } if (_outport.IsConnected()) { _outport.Send(p); } else { Drop(p); } } tw.Close(); }
public override void Execute() /*throws Throwable*/ { int port = 0; string theString; Packet p = _port.Receive(); if (p != null) { string portno = p.Content.ToString(); port = Int32.Parse(portno); Drop(p); _port.Close(); } TcpClient tcpClient; try { tcpClient = new TcpClient("localhost", port); } catch { Console.Error.WriteLine( "Failed to connect to server at {0}:{1}", "localhost", port); return; } NetworkStream networkStream = tcpClient.GetStream(); System.IO.StreamReader streamReader = new System.IO.StreamReader(networkStream); System.IO.StreamWriter streamWriter = new System.IO.StreamWriter(networkStream); int cyclic_count = 0; while ((p = _inport.Receive()) != null) { try { string s = String.Format("{0:D4}", cyclic_count); streamWriter.WriteLine(s + ":" + p.Content); //Console.WriteLine("WS write: " + p.Content); streamWriter.Flush(); ///* Experimental //if (cyclic_count % 20 == 0) //{ LongWaitStart(_timeout); theString = streamReader.ReadLine(); //Console.WriteLine("WS ack: " + theString); LongWaitEnd(); // } //*/ } catch { Console.Error.WriteLine("Exception reading from Server"); } if (_outport.IsConnected()) { _outport.Send(p); } else { Drop(p); } cyclic_count = (cyclic_count + 1) % 10000; } streamWriter.WriteLine("Closedown"); Console.WriteLine(this.Name + " Closing"); streamWriter.Flush(); networkStream.Close(); streamReader.Close(); streamWriter.Close(); }