示例#1
0
文件: GenSS.cs 项目: krattai/flosh
        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();
        }
示例#2
0
        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);
                    }
                }
            }
        }
示例#3
0
        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++);
                }
            }
        }
示例#4
0
        public override void Execute()
        {
            var p = _iipPort.Receive();

            if (p != null)
            {
                _iip = p.Content;
                //send first IIP on self start
                if (!_initialIIPSent)
                {
                    _outPort.Send(Create(_iip));
                    _initialIIPSent = true;
                }
                Drop(p);
                _iipPort.Close();
            }

            p = _truePort.Receive();
            if (p != null)
            {
                if (p.Content is bool b)
                {
                    if (b)
                    {
                        _outPort.Send(Create(_iip));
                    }
                    else
                    {
                        _truePort.Close();
                    }
                }
                Drop(p);
            }

            p = _falsePort.Receive();
            if (p != null)
            {
                if (p.Content is bool b)
                {
                    if (!b)
                    {
                        _outPort.Send(Create(_iip));
                    }
                    else
                    {
                        _falsePort.Close();
                    }
                }
                Drop(p);
            }
        }
示例#5
0
        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);
        }
示例#6
0
        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);
                }
            }
        }
示例#7
0
        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); }
        }
示例#8
0
        // make it a non-looper
        public override void Execute() /* throws Throwable */
        {
            Packet p = _inport.Receive();

            _outport.Send(p);
            System.Threading.Thread.Sleep(100);
        }
示例#9
0
        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);
            }
        }
示例#10
0
文件: DirList.cs 项目: krattai/flosh
        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));
            }
        }
示例#11
0
文件: Match.cs 项目: krattai/flosh
        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);
                }
            }
        }
示例#12
0
文件: Inject.cs 项目: krattai/flosh
        public override void Execute() /* throws Throwable  */
        {
            Packet p = _inport.Receive();

            _outport.Send(p);
            _inport.Close();
        }
示例#13
0
        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); }
            }
        }
示例#14
0
        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);
        }
示例#15
0
        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);
            }
        }
示例#16
0
        public override void Execute()
        {
            Packet p = _textPort.Receive();

            if (p != null)
            {
                var c = p.Content?.ToString().ToUpper();
                _text = c == "TRUE" || c == "YES";
                Drop(p);
                _textPort.Close();
            }

            if ((p = _inPort.Receive()) != null)
            {
                if (p.Content is ST st)
                {
                    if (_text)
                    {
                        _outPort.Send(Create(st.Value));
                    }
                    else
                    {
                        switch (st.Structure.which)
                        {
                        case ST.structure.WHICH.Json:
                            var jt = JToken.Parse(st.Value);
                            _outPort.Send(Create(jt));
                            break;

                        case ST.structure.WHICH.Xml:
                            var xml = XDocument.Parse(st.Value);
                            _outPort.Send(Create(xml));
                            break;

                        case ST.structure.WHICH.None:
                            _outPort.Send(Create(st.Value));
                            break;

                        default:
                            _outPort.Send(Create(st.Value));
                            break;
                        }
                    }
                }
                Drop(p);
            }
        }
示例#17
0
        // 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);
            }
        }
示例#18
0
 public override void Execute() /* throws Throwable */
 {
     for (int i = 0; i < 100; i++)
     {
         Packet p = Create(i);
         Thread.Sleep(100);
         _outport.Send(p);
     }
 }
示例#19
0
文件: ReadOdbc.cs 项目: krattai/flosh
        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
        }
示例#20
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);
            }
        }
示例#21
0
        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);
            }
        }
示例#22
0
        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);
        }
示例#23
0
        // 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);
        }
示例#24
0
        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);
            }
        }
示例#25
0
        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);
            }
        }
示例#26
0
        public override void Execute()
        {
            Packet p;
            string record = "";

            while ((p = _inp.Receive()) != null)
            {
                string word = p.Content.ToString();

                if (record.Length >= _reclen)
                {
                    _outdp.Send(Create(record));
                    record = "";
                }
                record += word + " ";
                _outp.Send(p);
            }
            if (record.Length > 0)
            {
                _outdp.Send(Create(record));
            }
        }
示例#27
0
        public override void Execute() /* throws Throwable  */
        {
            int no = _inportArray.Length;

            Packet p;

            for (int i = 0; i < no; i++)
            {
                while ((p = _inportArray[i].Receive()) != null)
                {
                    _outport.Send(p);
                }
            }
        }
示例#28
0
        public override void Execute()
        {
            Packet p = _confPort.Receive();

            if (p != null)
            {
                try
                {
                    var conf = JObject.Parse(p.Content?.ToString() ?? "{}");
                    _at            = conf["split-at"]?.Value <string>() ?? _at;
                    _addSSBrackets = conf["add-brackets"]?.Value <bool>() ?? _addSSBrackets;
                    _trim          = conf["trim"]?.Value <bool>() ?? _trim;
                }
                catch (JsonReaderException) { }
                Drop(p);
                _confPort.Close();
            }

            while ((p = _inPort.Receive()) != null)
            {
                var str = p.Content.ToString();
                Drop(p);
                var strs = str.Split(_at).Select(s => _trim ? s.Trim() : s);
                if (strs.Count() > 1 && _addSSBrackets)
                {
                    _outPort.Send(Create(Packet.Types.Open, ""));
                }
                foreach (var s in strs)
                {
                    _outPort.Send(Create(s));
                }
                if (strs.Count() > 1 && _addSSBrackets)
                {
                    _outPort.Send(Create(Packet.Types.Close, ""));
                }
            }
        }
示例#29
0
        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);
            }
        }
示例#30
0
        double _timeout = 1.5;         // 1.5 secs

        public override void Execute() /* throws Throwable*/
        {
            Packet p = _cfgp.Receive();

            if (p != null)
            {
                string param = p.Content.ToString();
                _timeout = Double.Parse(param);
                Drop(p);
                _cfgp.Close();
            }

            Packet rp = _source.Receive();

            _source.Close();

            if (rp == null)
            {
                return;
            }
            Object       o  = rp.Content;
            StreamReader sr = null;

            if (o is String)
            {
                String st = (String)o;
                sr = new StreamReader(st);
            }
            else
            {
                Stream str = (Stream)o;
                sr = new StreamReader(str);
            }
            Drop(rp);

            string s;
            int    no = 0;

            while ((s = ReadLine(sr)) != null)
            {
                no++;
                p = Create(s);
                _outport.Send(p);
            }

            sr.Close();
            Console.Out.WriteLine("Number of lines read: {0}", no);
        }