public override void Execute() { Regex regex = null; Packet p = _cfgp.Receive(); string pattern = p.Content.ToString(); try { regex = new Regex(pattern); } catch (Exception) { FlowError.Complain("invalid regular expression " + pattern); } Drop(p); _cfgp.Close(); for (p = _inp.Receive(); p != null; p = _inp.Receive()) { if (regex.IsMatch(p.Content.ToString())) { _outp.Send(p); } else { _outpn.Send(p); } } }
// make it a non-looper public override void Execute() /* throws Throwable */ { Packet p; for (p = _inport.Receive(); p != null; p = _inport.Receive()) { _outport.Send(p); } }
public override void Execute() /* throws Throwable */ { Packet ctp = _count.Receive(); string param = ctp.Content.ToString(); Int32 ct = Int32.Parse(param); Drop(ctp); _count.Close(); Packet p = Create(Packet.Types.Open, ""); _outport.Send(p); for (int i = 0; i < ct; i++) { if (i % 20 == 4) { p = Create(Packet.Types.Close, ""); _outport.Send(p); p = Create(Packet.Types.Open, ""); _outport.Send(p); } int j = 100 - i; string s = String.Format("{0:d4}", j) + " abc"; p = Create(s); _outport.Send(p); } p = Create(Packet.Types.Close, ""); _outport.Send(p); // output.close(); // terminate(); }
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 = _cfgp.Receive(); if (p != null) { string param = p.Content.ToString(); _timeout = Double.Parse(param); Drop(p); _cfgp.Close(); } Packet p0 = _inp.Receive(); string path = p0.Content as string; if (path != null) { TextReader tr = new StreamReader(path); string blob = ReadBlobItem(tr); p = Create(blob); p.Attributes.Add("Path", path); _outp.Send(p); } Drop(p0); }
public override void Execute() { var p = _inPort.Receive(); if (p == null) { return; } var str = p.Content.ToString(); Drop(p); List <string> envVars = new(); var start = 0; while (true) { var i = str.IndexOf("${", start); if (i == -1) { break; } var varStart = i + 2; var e = str.IndexOf("}", varStart); if (e == -1) { break; } var afterVarEnd = e; if (varStart < afterVarEnd) { envVars.Add(str[varStart..afterVarEnd]);
// make it a non-looper public override void Execute() /* throws Throwable */ { Packet p = _inport.Receive(); _outport.Send(p); System.Threading.Thread.Sleep(100); }
public override void Execute() { Packet p = _inPort.Receive(); Mas.Rpc.Climate.ITimeSeries timeSeries = null; if (p != null) { timeSeries = p.Content as Mas.Rpc.Climate.ITimeSeries; Drop(p); _inPort.Close(); } if (timeSeries != null) { try { var header = timeSeries.Header().Result; var hl = header.Select(h => h.ToString()).ToList(); p = Create(hl); _outPort.Send(p); timeSeries.Dispose(); } catch (RpcException e) { Console.WriteLine(e.Message); } } }
public override void Execute() { Packet p = _keyPort.Receive(); if (p != null) { _key = p.Content?.ToString() ?? _key; Drop(p); _keyPort.Close(); } object val = null; if ((p = _valPort.Receive()) != null) { val = p.Content; Drop(p); } if ((p = _inPort.Receive()) != null) { if (p.Type == Packet.Types.Normal) { p.Attributes[_key] = val; } _outPort.Send(p); } }
public override void Execute() { Packet p; if (null != (p = _cfgp.Receive())) { string param = p.Content.ToString(); string[] words = param.Split(','); _wordoff = Int32.Parse(words[0]); _linlen = Int32.Parse(words[1]); Drop(p); _cfgp.Close(); } p = _inp.Receive(); string word = p.Content.ToString(); string text = p.Attributes["Text"] as string; text = new string(' ', _linlen) + text + new string(' ', _linlen); int offset = (int)p.Attributes["Offset"]; int i = offset + _linlen - _wordoff; int j = text.Length - i; j = j < _linlen ? j : _linlen; string line = text.Substring(i, j); line = line.Substring(0, _wordoff) + "*" + line.Substring(_wordoff); _outp.Send(Create(line)); Drop(p); }
public override void Execute() { Packet p; while ((p = _inPort.Receive()) != null) { if (p.Attributes.ContainsKey("rest") && p.Attributes["rest"] is ST rst) { Model.Env <ST> env = new() { Rest = rst }; if (p.Attributes.ContainsKey("time-series") && p.Attributes["time-series"] is Climate.ITimeSeries ts) { env.TimeSeries = ts; } if (p.Attributes.ContainsKey("soil-profile") && p.Attributes["soil-profile"] is Soil.Profile sp) { env.SoilProfile = sp; } if (p.Attributes.ContainsKey("mgmt-events") && p.Attributes["mgmt-events"] is IEnumerable <Mgmt.Event> mes) { env.MgmtEvents = mes.ToList(); } var p2 = Create(env); _outPort.Send(p2); } Drop(p); } }
public override void Execute() /* throws Throwable */ { int no = _outportArray.Length; Packet p; long count = 0; while ((p = _inport.Receive()) != null) { ++count; string o = (string)p.Content; Drop(p); for (int i = 0; i < no; i++) { string o2 = o + ""; Packet p2 = Create(o2); _outportArray[i].Send(p2); // else System.out.println( "Line written " + count + " by" + getName()); } } Console.Out.WriteLine("Repl complete. " + Name); }
public override void Execute() { Packet p; int level = 1; while ((p = _inport.Receive()) != null) { switch (p.Type) { case Packet.Types.Open: Console.Out.WriteLine("OPEN(" + level + ")"); level++; break; case Packet.Types.Close: level--; Console.Out.WriteLine("CLOSE(" + level + ")"); break; default: Console.Out.WriteLine(p.Content); break; } Drop(p); } }
public override void Execute() { Packet p = _sturdyRefPort.Receive(); if (p != null) { _sturdyRef = p.Content.ToString(); Drop(p); _sturdyRefPort.Close(); } try { if (ConMan() == null) { return; } using var timeSeries = ConMan().Connect <Mas.Rpc.Climate.ITimeSeries>(_sturdyRef).Result; //var header = timeSeries.Header().Result; //var hl = header.Select(h => h.ToString()).ToList(); //Console.WriteLine(hl.Aggregate((a, v) => a + " | " + v)); //p = Create(hl); p = Create(Capnp.Rpc.Proxy.Share(timeSeries)); _outPort.Send(p); } catch (RpcException e) { Console.WriteLine(e.Message); } }
public override void Execute() { Packet p = _inPort.Receive(); if (p != null) { if (p.Content is ICapnpSerializable obj) { int no = _outPortArray.Length; var msg = MessageBuilder.Create(); var root = msg.BuildRoot <LatLonCoord.WRITER>(); obj.Serialize(root); var type = obj.GetType(); ConstructorInfo ci = type.GetConstructor(Type.EmptyTypes); for (int i = 0; i < no; i++) { if (ci.Invoke(null) is ICapnpSerializable copy) { copy.Deserialize(root); _outPortArray[i].Send(Create(copy)); } } } Drop(p); } }
public override void Execute() { Packet np = _nameport.Receive(); if (np == null) { return; } _nameport.Close(); string pname = np.Content as string; Drop(np); _outport = (_mother._outputPorts)[pname] as OutputPort; _mother.Trace(Name + ": Accessing output port: " + _outport.Name); _outport.SetSender(this); Packet p; while ((p = _inport.Receive()) != null) { _outport.Send(p); } // outport.close(); _mother.Trace(Name + ": Releasing output port: " + _outport.Name); _outport = null; }
public override void Execute() /* throws Throwable */ { Packet p = _inport.Receive(); _outport.Send(p); _inport.Close(); }
public override void Execute() { Packet p = _inp.Receive(); string name = p.Content.ToString(); _outp.Send(p); _inp.Close(); DirectoryInfo di = new DirectoryInfo(name); DirectoryInfo[] dirs = di.GetDirectories(); if (dirs.Length == 0) { FlowError.Complain("Missing directory"); } foreach (DirectoryInfo d in dirs) { _outpd.Send(Create(d.FullName)); } FileInfo[] files = di.GetFiles(); foreach (FileInfo f in files) { _outpf.Send(Create(f.FullName)); } }
public override void Execute() { Packet p = _dictPort.Receive(); if (p != null) { _dict = p.Content; Drop(p); } // we need a dictstruct in order to continue if (_dict == null) { FlowError.Complain("DictGetValue(" + Name + ").DICT: No dictionary in IP."); } p = _keyPort.Receive(); if (p != null) { var keys = p.Content?.ToString() ?? ""; _keys = keys.Split(' '); Drop(p); } // we need at least a property name to continue if (!_keys.Any()) { FlowError.Complain("DictGetValue(" + Name + ").KEYS: No keys in IP."); } if (_outPorts.Length != _keys.Length) { FlowError.Complain("DictGetValue(" + Name + "): Number of connected VAL ports doesn't match number of keys."); } foreach (var(valPort, i) in _outPorts.Select((vp, i) => (vp, i))) { try { try { if (_dict.ContainsKey(_keys[i])) { valPort.Send(Create(_dict[_keys[i]])); } } catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException) { // try Contains from IDictionary if (_dict.Contains(_keys[i])) { valPort.Send(Create(_dict[_keys[i]])); } } } catch (System.Exception e) { FlowError.Complain("DictGetValue(" + Name + "): Exception: " + e.Message); } } }
// copy 30 packets at a time to consecutive output ports // close each port as it is finished // send all excess output to the last port public override void Execute() { int i = 0; int count = 0; for (Packet p = _inp.Receive(); p != null; p = _inp.Receive()) { // Console.Out.WriteLine("{0} {1}", count, i); _outps[i].Send(p); if (++count == 30 && i != _outps.Length - 1) { _outps[i].Close(); i++; count = 0; } } }
public override void Execute() { Packet p = _capPort.Receive(); if (p != null) { _cap = p.Content as Proxy; Drop(p); } // we need a capability in order to continue if (_cap == null) { return; } p = _msgPort.Receive(); if (p != null) { var msgName = p.Content.ToString(); var t = _cap.GetType(); _method = t.GetMethod(msgName); Drop(p); } // we need a method to continue if (_method == null) { return; } var no = _paramsPort.Length; _params = new object[no + 1]; _params[no] = null; for (var i = 0; i < no; i++) { p = _paramsPort[i].Receive(); if (p != null) { _params[i] = p.Content; Drop(p); } } try { dynamic r = _method.Invoke(_cap, _params); _outPort.Send(Create(r.Result)); } catch (System.Exception e) { FlowError.Complain("SendMessage(" + Name + "): Exception: " + e.Message); } }
public override void Execute() { Packet p = _cfgp.Receive(); string parms = p.Content as string; Drop(p); _cfgp.Close(); string[] parmArray = parms.Split(','); _dsn = parmArray[0]; _query = parmArray[1]; _table = parmArray[2]; _timeout = Double.Parse(parmArray[3]); OdbcConnection conn = new OdbcConnection(_dsn); OdbcCommand cmd = new OdbcCommand(_query, conn); OdbcDataReader rdr = null; try { conn.Open(); } catch (Exception e) { FlowError.Complain("cannot open connection"); } try { rdr = cmd.ExecuteReader(); } catch (Exception e) { FlowError.Complain("cannot execute query"); } List <string> columns = new List <string>(); for (int i = 0; i < rdr.FieldCount; ++i) { columns.Add(rdr.GetName(i)); } int serialno = 0; while (ReadOdbcRow(rdr)) { Record rec = new Record(_table, columns.ToArray()); for (int i = 0; i < rdr.FieldCount; ++i) { rec[i] = rdr[i]; } p = Create(rec); p.Attributes["SerialNo"] = ++serialno; _outp.Send(p); } // _outp.Close( ); --not needed }
public override void Execute() { Packet p = _tempPort.Receive(); if (p != null) { _temp = p.Content?.ToString(); Drop(p); } p = _confPort.Receive(); if (p != null) { _placeholderNames = p.Content?.ToString().Split(' ') ?? System.Array.Empty <string>(); Drop(p); } // continue only if we got a template if (_temp == null) { return; } while ((p = _inPort.Receive()) != null) { var o = p.Content ?? ""; Drop(p); if (o is string strVal) { foreach (var name in _placeholderNames) { var repl = _temp.Replace("${" + name + "}", strVal); _outPort.Send(Create(repl)); } } else //if (o is System.Collections.Generic.IDictionary<string, JToken> dict) { var od = o as dynamic; var repl = _temp.Clone() as string; try { foreach (var name in _placeholderNames) { var str = od.ContainsKey(name) ? od[name].ToString() : ""; repl = repl.Replace("${" + name + "}", str); } _outPort.Send(Create(repl)); } catch (System.Exception e) { FlowError.Complain("TextInterpolate(" + Name + ").IN delivered unknown object type. Exception: " + e.Message); } } } }
public override void Execute() { Packet p = _keyPort.Receive(); if (p != null) { _key = p.Content?.ToString() ?? _key; Drop(p); _keyPort.Close(); } if ((p = _valPort.Receive()) != null) { _val = p.Content; Drop(p); _valPort.Close(); } if ((p = _methPort.Receive()) != null) { _met = p.Content?.ToString(); Drop(p); _methPort.Close(); } if ((p = _inPort.Receive()) != null) { if (p.Type == Packet.Types.Normal) { if (!string.IsNullOrEmpty(_met)) { var t = _val.GetType(); var m = t.GetMethod(_met); var clone = m.Invoke(_val, null); if (clone != null) { p.Attributes[_key] = clone; } } else { if (_val is System.ValueType vt) { p.Attributes[_key] = vt; } else if (_val is System.ICloneable c) { p.Attributes[_key] = c.Clone(); } } } _outPort.Send(p); } }
Regex _rgx2 = new Regex(@"\s+"); //at least one blank // make it a non-looper public override void Execute() /* throws Throwable */ { Packet p = _inport.Receive(); string text = p.Content as string; text = _rgx.Replace(text, " "); // special characters -> spaces text = _rgx2.Replace(text, " "); // collapse multiple spaces text = text.Trim(); // remove leading and trailing spaces p.Content = text; _outport.Send(p); }
// make it a non-looper public override void Execute() /* throws Throwable */ { Packet p = _inport.Receive(); Random rnd = new Random(); LongWaitStart(1); int no = rnd.Next(0, 200); System.Threading.Thread.Sleep(no); LongWaitEnd(); _outport.Send(p); }
public override void Execute() { Packet p = _objPort.Receive(); if (p != null) { _obj = p.Content; Drop(p); } // we need an object in order to continue if (_obj == null) { return; } p = _methPort.Receive(); if (p != null) { var methName = p.Content?.ToString() ?? ""; var t = _obj.GetType(); _method = t.GetMethod(methName); Drop(p); } // we need a method to continue if (_method == null) { return; } var no = _paramsPort.Length; _params = new object[no]; for (var i = 0; i < no; i++) { p = _paramsPort[i].Receive(); if (p != null) { _params[i] = p.Content; Drop(p); } } try { var res = _method.Invoke(_obj, _params); _outPort.Send(Create(res)); } catch (System.Exception e) { Console.WriteLine("Exception: " + e.Message); } }
public override void Execute() { Packet p = _typePort.Receive(); if (p != null) { var str = p.Content.ToString()?.ToUpper(); Drop(p); _typePort.Close(); if (str != null) { if (str == "XML") { _structure = new ST.structure { which = ST.structure.WHICH.Xml } } ; else if (str == "JSON") { _structure = new ST.structure { which = ST.structure.WHICH.Json } } ; else if (str == "NONE") { _structure = new ST.structure { which = ST.structure.WHICH.None } } ; } } p = _inPort.Receive(); if (p != null) { var content = p.Content.ToString(); Drop(p); if (content == null) { return; } var st = new ST() { Structure = _structure, Value = content }; p = Create(st); _outPort.Send(p); } }
public override void Execute() { Packet p = _inPort.Receive(); if (p != null) { var str = p.Content.ToString(); Drop(p); try { var ll = str.Split(',').Select(v => double.Parse(v, CultureInfo.CreateSpecificCulture("en-US"))).ToArray(); _outPort.Send(Create(new LatLonCoord { Lat = ll[0], Lon = ll[1] })); } catch (System.Exception e) { Console.WriteLine("Exception in CreateLatLonCoord receiving []: [" + str + "] Exception: " + e.Message); } } Packet latp = _latPort.Receive(); if (latp == null) { // close also lonPort, because lat/lon have to go together _lonPort.Close(); } else { Packet lonp = _lonPort.Receive(); if (lonp == null) { if (latp != null) { Drop(latp); // lat and lon packets have to go together _latPort.Close(); } } else { var lat = (double)(latp.Content as Newtonsoft.Json.Linq.JValue); Drop(latp); var lon = (double)(lonp.Content as Newtonsoft.Json.Linq.JValue); Drop(lonp); _outPort.Send(Create(new LatLonCoord { Lat = lat, Lon = lon })); //Console.WriteLine("created LLCs: " + _count++); } } }
public override void Execute() { Packet p = _methPort.Receive(); if (p != null) { _met = p.Content?.ToString(); Drop(p); } p = _inPort.Receive(); if (p != null) { var obj = p.Content; Drop(p); if (obj != null) { int no = _outPortArray.Length; if (!string.IsNullOrEmpty(_met)) { var t = obj.GetType(); var m = t.GetMethod(_met); for (int i = 0; i < no; i++) { var clone = m.Invoke(obj, null); if (clone != null) { _outPortArray[i].Send(Create(clone)); } } } else { if (obj is System.ValueType vt) { for (int i = 0; i < no; i++) { _outPortArray[i].Send(Create(vt)); } } else if (obj is System.ICloneable c) { for (int i = 0; i < no; i++) { _outPortArray[i].Send(Create(c.Clone())); } } } } } }