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); } } }
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); } } }
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 = _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 = _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 void GetFlowErrorStringTest() { var errorMessage = "Das ist ein Fehler!"; var resolveMessage = "Zur Lösung bitte das machen..."; var referenceflow = 0; var flowError = new FlowError(referenceflow, resolveMessage, errorMessage); var expectedResult = "Fehler in Flow " + (referenceflow + 1) + ": " + errorMessage + "\t" + resolveMessage + "\r\n"; Assert.IsTrue(flowError.ToString() == expectedResult); }
public override void Execute() { //* if (ConMan() == null) { FlowError.Complain("ConnectToSturdyRef(" + Name + "): No ConnectionManager instance available."); } //*/ // read mandatory sturdy ref to connect to Packet p = _sturdyRefPort.Receive(); if (p != null) { _sturdyRef = p.Content.ToString(); Drop(p); } if (string.IsNullOrEmpty(_sturdyRef)) { FlowError.Complain("ConnectToSturdyRef(" + Name + ").IN: Received sturdy ref is invalid or empty."); } // read a string this component will convert to a type p = _capTypePort.Receive(); if (p != null) { _capType = SupportedTypes.GetValueOrDefault(p.Content.ToString(), _capType); Drop(p); if (_capType == null) { FlowError.Complain("ConnectToSturdyRef(" + Name + ").TYPE: Received capability type is unknown."); } } try { dynamic task = typeof(InfraCommon.ConnectionManager) .GetMethod("Connect") .MakeGenericMethod(_capType) .Invoke(ConMan(), new object[] { _sturdyRef }); _outPort.Send(Create(task.Result)); } catch (System.Exception e) { FlowError.Complain("ConnectToSturdyRef(" + Name + "): Exception: " + e.Message); } }
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() { 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 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() { Packet p = _capPort.Receive(); if (p != null) { _cap = p.Content as Grid.IGrid; Drop(p); } if (_cap == null) { p = _srPort.Receive(); if (p != null) { _sturdyRef = p.Content?.ToString(); Drop(p); if (_sturdyRef != null) { try { if (ConMan() == null) { FlowError.Complain("CapnpAccessGridService(" + Name + "): No ConnectionManager instance available."); } _cap = ConMan().Connect <Grid.IGrid>(_sturdyRef).Result; } catch (System.Exception e) { FlowError.Complain("CapnpAccessGridService(" + Name + "): Exception: " + e.Message); } } else { FlowError.Complain("CapnpAccessGridService(" + Name + ").SR: Received sturdy ref is invalid or empty."); } } } // we need a capability in order to continue if (_cap == null) { FlowError.Complain("CapnpAccessGridService(" + Name + ").CAP/SR: No CAPability to use or SturdyRef to connect to."); } string msg = "null"; p = _msgPort.Receive(); if (p != null) { msg = p.Content?.ToString() ?? msg; switch (msg.ToLower()) { case "closestvalueat": _msg = Msg.closestValueAt; break; case "valueat": _msg = Msg.valueAt; break; case "resolution": _msg = Msg.resolution; break; case "dimension": _msg = Msg.dimension; break; case "nodatavalue": _msg = Msg.noDataValue; break; case "latlonbounds": _msg = Msg.latLonBounds; break; case "streamcells": _msg = Msg.streamCells; break; default: _msg = Msg.unknown; break; } Drop(p); } // we need a method to continue if (_msg == Msg.unknown) { FlowError.Complain("CapnpAccessGridService(" + Name + ").MSG: Unknown message. MSG: " + msg); } try { switch (_msg) { case Msg.closestValueAt: Geo.LatLonCoord llc = null; if (_paramsPort.Length > 0) { p = _paramsPort[0].Receive(); if (p != null) { llc = p.Content as Geo.LatLonCoord; Drop(p); } } if (llc == null) { FlowError.Complain("CapnpAccessGridService(" + Name + ").PARAM[0]: No latLonCoord supplied."); } bool ignoreNoData = true; if (_paramsPort.Length > 1) { p = _paramsPort[1].Receive(); if (p != null) { ignoreNoData = p.Content as bool? ?? ignoreNoData; Drop(p); } } ulong resolution = 0; if (_paramsPort.Length > 2) { p = _paramsPort[2].Receive(); if (p != null) { resolution = p.Content as ulong? ?? resolution; Drop(p); } } Grid.Aggregation agg = Grid.Aggregation.none; if (_paramsPort.Length > 3) { p = _paramsPort[3].Receive(); if (p != null) { switch ((p.Content?.ToString() ?? "none").ToLower()) { case "avg": agg = Grid.Aggregation.avg; break; case "wavg": agg = Grid.Aggregation.wAvg; break; case "iavg": agg = Grid.Aggregation.iAvg; break; case "median": agg = Grid.Aggregation.median; break; case "wmedian": agg = Grid.Aggregation.wMedian; break; case "imedian": agg = Grid.Aggregation.iMedian; break; case "min": agg = Grid.Aggregation.min; break; case "wmin": agg = Grid.Aggregation.wMin; break; case "imin": agg = Grid.Aggregation.iMin; break; case "max": agg = Grid.Aggregation.max; break; case "wmax": agg = Grid.Aggregation.wMax; break; case "imax": agg = Grid.Aggregation.iMax; break; case "sum": agg = Grid.Aggregation.sum; break; case "wsum": agg = Grid.Aggregation.wSum; break; case "isum": agg = Grid.Aggregation.iSum; break; default: agg = Grid.Aggregation.none; break; } Drop(p); } } bool returnRowCols = false; if (_paramsPort.Length > 4) { p = _paramsPort[4].Receive(); if (p != null) { returnRowCols = p.Content as bool? ?? returnRowCols; Drop(p); } } bool includeAggParts = false; if (_paramsPort.Length > 5) { p = _paramsPort[5].Receive(); if (p != null) { includeAggParts = p.Content as bool? ?? includeAggParts; Drop(p); } } var r = _cap.ClosestValueAt(llc, ignoreNoData, resolution, agg, returnRowCols, includeAggParts); _outPort.Send(Create(r.Result)); break; } } catch (System.Exception e) { FlowError.Complain("CapnpAccessGridService(" + Name + "): Exception: " + e.Message); } }