// Depart from Java - This has a method where mimetype selection can be specified - NOTE: This toolkit // does not yet support a JsonReader public HGrid invokeAction(HRef id, string action, HDict args, string mimetype) { HDict meta = new HDictBuilder().add("id", id).add("action", action).toDict(); HGrid req = HGridBuilder.dictsToGrid(meta, new HDict[] { args }); return(call("invokeAction", req, mimetype)); }
public override void unsub(HRef[] ids) { if (ids.Length == 0) { throw new ArgumentException("ids are empty", "ids"); } if (ID == null) { throw new InvalidOperationException("nothing subscribed yet"); } if (Closed) { throw new InvalidOperationException("watch is closed"); } // grid meta HGridBuilder b = new HGridBuilder(); b.Meta.add("watchId", ID); // grid rows b.addCol("id"); for (int i = 0; i < ids.Length; ++i) { b.addRow(new HVal[] { ids[i] }); } // make request HGrid req = b.toGrid(); m_client.call("watchUnsub", req); }
public void watchClose(HClientWatch w, bool bSend) { // mark flag on watch itself, short circuit if already closed if (w.Closed) { return; } w.Closed = true; // remove it from my lookup table if (w.ID != null) { m_watches_Renamed.Remove(w.ID); } // optionally send close message to server if (bSend) { try { HGridBuilder b = new HGridBuilder(); b.Meta.add("watchId", w.ID).add("close"); b.addCol("id"); call("watchUnsub", b.toGrid()); } catch (Exception /*e*/) { // YET TO DO - we aren't doing anything here, why? } } }
public HGrid pollChanges(bool bRefresh) { if (ID == null) { throw new InvalidOperationException("nothing subscribed yet"); } if (Closed) { throw new InvalidOperationException("watch is closed"); } // grid meta HGridBuilder b = new HGridBuilder(); b.Meta.add("watchId", ID); if (bRefresh) { b.Meta.add("refresh"); } b.addCol("empty"); // make request HGrid req = b.toGrid(); try { return(m_client.call("watchPoll", req)); } catch (CallErrException e) { // any server side error is considered close close(false); throw e; } }
public void testNoRows() { HGridBuilder b = new HGridBuilder(); b.Meta.add("dis", "Title"); b.addCol("a").add("dis", "Alpha"); b.addCol("b"); HGrid g = b.toGrid(); // meta Assert.AreEqual(g.meta.size(), 1); Assert.IsTrue(g.meta.get("dis").hequals(HStr.make("Title"))); // cols HCol c; Assert.AreEqual(g.numCols, 2); c = verifyCol(g, 0, "a"); Assert.AreEqual(c.dis(), "Alpha"); Assert.AreEqual(c.meta.size(), 1); Assert.IsTrue(c.meta.get("dis").hequals(HStr.make("Alpha"))); // rows Assert.AreEqual(g.numRows, 0); Assert.AreEqual(g.isEmpty(), true); // iterator verifyGridIterator(g); }
public Task <HGrid> hisWriteAsync(HRef id, HHisItem[] items) { HDict meta = new HDictBuilder().add("id", id).toDict(); HGrid req = HGridBuilder.hisItemsToGrid(meta, items); return(CallAsync("hisWrite", req, "text/zinc")); }
public void close(bool bSend) { // mark flag on watch itself, short circuit if already closed if (Closed) { return; } Closed = true; // optionally send close message to server if (bSend) { try { HGridBuilder b = new HGridBuilder(); b.Meta.add("watchId", ID).add("close"); b.addCol("id"); m_client.call("watchUnsub", b.toGrid()); } catch (Exception /*e*/) { // YET TO DO - we aren't doing anything here, why? } } }
/** * Write a set of history time-series data to the given point record. * The record must already be defined and must be properly tagged as * a historized point. The timestamp timezone must exactly match the * point's configured "tz" tag. If duplicate or out-of-order items are * inserted then they must be gracefully merged. */ public override void hisWrite(HRef id, HHisItem[] items) { HDict meta = new HDictBuilder().add("id", id).toDict(); HGrid req = HGridBuilder.hisItemsToGrid(meta, items); call("hisWrite", req); }
public void testSimple() { HGridBuilder b = new HGridBuilder(); b.addCol("id"); b.addCol("dis"); b.addCol("area"); b.addRow(new HVal[] { HRef.make("a"), HStr.make("Alpha"), HNum.make(1200) }); b.addRow(new HVal[] { HRef.make("b"), null, HNum.make(1400) }); // meta HGrid g = b.toGrid(); Assert.AreEqual(g.meta.size(), 0); // cols //HCol c; Assert.AreEqual(g.numCols, 3); verifyCol(g, 0, "id"); verifyCol(g, 1, "dis"); verifyCol(g, 2, "area"); // rows Assert.AreEqual(g.numRows, 2); Assert.IsFalse(g.isEmpty()); HRow r; r = g.row(0); Assert.IsTrue(r.get("id").hequals(HRef.make("a"))); Assert.IsTrue(r.get("dis").hequals(HStr.make("Alpha"))); Assert.IsTrue(r.get("area").hequals(HNum.make(1200))); r = g.row(1); Assert.IsTrue(r.get("id").hequals(HRef.make("b"))); Assert.IsNull(r.get("dis", false)); Assert.IsTrue(r.get("area").hequals(HNum.make(1400))); try { r.get("dis"); Assert.Fail(); } catch (UnknownNameException) { Assert.IsTrue(true); } Assert.IsNull(r.get("fooBar", false)); try { r.get("fooBar"); Assert.Fail(); } catch (UnknownNameException) { Assert.IsTrue(true); } // HRow no-nulls HRow it = g.row(0); Assert.IsFalse(it.Size > 3); verifyRowIterator(it, 0, "id", HRef.make("a")); verifyRowIterator(it, 1, "dis", HStr.make("Alpha")); verifyRowIterator(it, 2, "area", HNum.make(1200)); // HRow with nulls it = g.row(1); Assert.IsFalse(it.Size > 3); verifyRowIterator(it, 0, "id", HRef.make("b")); verifyRowIterator(it, 2, "area", HNum.make(1400)); // iterating verifyGridIterator(g); }
////////////////////////////////////////////////////////////////////////// // Evals ////////////////////////////////////////////////////////////////////////// /** * Call "eval" operation to evaluate a vendor specific * expression on the server: * - SkySpark: any Axon expression * * Raise CallErrException if the server raises an exception. */ public HGrid eval(string expr) { HGridBuilder b = new HGridBuilder(); b.addCol("expr"); b.addRow(new HVal[] { HStr.make(expr) }); HGrid req = b.toGrid(); return(call("eval", req)); }
protected override HGrid onReadAll(String filter, int limit) { HGridBuilder b = new HGridBuilder(); b.addCol("filter"); b.addCol("limit"); b.addRow(new HVal[] { HStr.make(filter), HNum.make(limit) }); HGrid req = b.toGrid(); return(call("read", req)); }
/** * Convenience for "evalAll(HGrid, checked)". */ public HGrid[] evalAll(string[] exprs, bool bChecked) { HGridBuilder b = new HGridBuilder(); b.addCol("expr"); for (int i = 0; i < exprs.Length; ++i) { b.addRow(new HVal[] { HStr.make(exprs[i]) }); } return(evalAll(b.toGrid(), bChecked)); }
////////////////////////////////////////////////////////////////////////// // History ////////////////////////////////////////////////////////////////////////// /** * Read history time-series data for given record and time range. The * items returned are exclusive of start time and inclusive of end time. * Raise exception if id does not map to a record with the required tags * "his" or "tz". The range may be either a String or a HDateTimeRange. * If HTimeDateRange is passed then must match the timezone configured on * the history record. Otherwise if a String is passed, it is resolved * relative to the history record's timezone. */ public override HGrid hisRead(HRef id, object range) { HGridBuilder b = new HGridBuilder(); b.addCol("id"); b.addCol("range"); b.addRow(new HVal[] { id, HStr.make(range.ToString()) }); HGrid req = b.toGrid(); HGrid res = call("hisRead", req); return(res); }
/** * Return the current status * of a point's priority array. * The result is returned grid with following columns: * <ul> * <li>level: number from 1 - 17 (17 is default) * <li>levelDis: human description of level * <li>val: current value at level or null * <li>who: who last controlled the value at this level * </ul> */ public HGrid pointWriteArray(HRef id) { HGridBuilder b = new HGridBuilder(); b.addCol("id"); b.addRow(new HVal[] { id }); HGrid req = b.toGrid(); HGrid res = call("pointWrite", req); return(res); }
protected override HGrid onReadByIds(HRef[] ids) { HGridBuilder b = new HGridBuilder(); b.addCol("id"); for (int i = 0; i < ids.Length; ++i) { b.addRow(new HVal[] { ids[i] }); } HGrid req = b.toGrid(); return(call("read", req)); }
public HGrid readByIds(HRef[] ids) { HGridBuilder b = new HGridBuilder(); b.addCol("id"); for (int i = 0; i < ids.Length; ++i) { b.addRow(new HVal[] { ids[i] }); } HGrid req = b.toGrid(); return(call("read", req, "text/zinc")); }
private IEnumerable <HRow> BuildRows(ICollection <string> cols, params HVal[][] rows) { var gridBuilder = new HGridBuilder(); foreach (var col in cols) { gridBuilder.addCol(col); } foreach (var row in rows) { gridBuilder.addRow(row); } return(gridBuilder.toGrid().Rows); }
public void testEmpty() { HGrid g = new HGridBuilder().toGrid(); Assert.AreEqual(g.meta, HDict.Empty); Assert.AreEqual(g.numRows, 0); Assert.IsTrue(g.isEmpty()); Assert.IsNull(g.col("foo", false)); try { g.col("foo"); Assert.Fail(); } catch (UnknownNameException) { Assert.IsTrue(true); } }
public Task <HGrid> readAllAsync(string filter, int limit) { HGridBuilder b = new HGridBuilder(); b.addCol("filter"); if (limit > 0) { b.addCol("limit"); b.addRow(new HVal[] { HStr.make(filter), HNum.make(limit) }); } else { b.addRow(new HVal[] { HStr.make(filter) }); } HGrid req = b.toGrid(); return(CallAsync("read", req, "text/zinc")); }
public void testWriter() { HGridBuilder gb = new HGridBuilder(); gb.addCol("a"); gb.addCol("b"); gb.addRow(new HVal[] { HNA.VAL, HBool.TRUE }); // Original Unit test had null - this is not valid gb.addRow(new HVal[] { HMarker.VAL, HNA.VAL }); gb.addRow(new HVal[] { HRemove.VAL, HNA.VAL }); gb.addRow(new HVal[] { HStr.make("test"), HStr.make("with:colon") }); gb.addRow(new HVal[] { HNum.make(12), HNum.make(72.3, "\u00b0F") }); gb.addRow(new HVal[] { HNum.make(double.NegativeInfinity), HNum.make(Double.NaN) }); gb.addRow(new HVal[] { HDate.make(2015, 6, 9), HTime.make(1, 2, 3) }); var tz = HTimeZone.make("UTC", true); gb.addRow(new HVal[] { HDateTime.make(634429600180690000L, tz), HUri.make("foo.txt") }); gb.addRow(new HVal[] { HRef.make("abc"), HRef.make("abc", "A B C") }); gb.addRow(new HVal[] { HBin.make("text/plain"), HCoord.make(90, -123) }); HGrid grid = gb.toGrid(); string actual = HJsonWriter.gridToString(grid); // System.out.println(actual); string[] lines = actual.Split('\n'); Assert.AreEqual(lines[0], "{"); Assert.AreEqual(lines[1], "\"meta\": {\"ver\":\"2.0\"},"); Assert.AreEqual(lines[2], "\"cols\":["); Assert.AreEqual(lines[3], "{\"name\":\"a\"},"); Assert.AreEqual(lines[4], "{\"name\":\"b\"}"); Assert.AreEqual(lines[5], "],"); Assert.AreEqual(lines[6], "\"rows\":["); Assert.AreEqual(lines[7], "{\"a\":\"z:\", \"b\":true},"); Assert.AreEqual(lines[8], "{\"a\":\"m:\", \"b\":\"z:\"},"); Assert.AreEqual(lines[9], "{\"a\":\"x:\", \"b\":\"z:\"},"); Assert.AreEqual(lines[10], "{\"a\":\"test\", \"b\":\"s:with:colon\"},"); Assert.AreEqual(lines[11], "{\"a\":\"n:12\", \"b\":\"n:72.3 \u00b0F\"},"); Assert.AreEqual(lines[12], "{\"a\":\"n:-INF\", \"b\":\"n:NaN\"},"); Assert.AreEqual(lines[13], "{\"a\":\"d:2015-06-09\", \"b\":\"h:01:02:03\"},"); Assert.AreEqual(lines[14], "{\"a\":\"t:2011-06-06T12:26:58.069Z UTC\", \"b\":\"u:foo.txt\"},"); Assert.AreEqual(lines[15], "{\"a\":\"r:abc\", \"b\":\"r:abc A B C\"},"); Assert.AreEqual(lines[16], "{\"a\":\"b:text/plain\", \"b\":\"c:90.0,-123.0\"}"); Assert.AreEqual(lines[17], "]"); Assert.AreEqual(lines[18], "}"); }
////////////////////////////////////////////////////////////////////////// // PointWrite ////////////////////////////////////////////////////////////////////////// /** * Write to a given level of a writable point, and return the current status * of a writable point's priority array (see pointWriteArray()). * * @param id Ref identifier of writable point * @param level Number from 1-17 for level to write * @param val value to write or null to auto the level * @param who optional username performing the write, otherwise user dis is used * @param dur Number with duration unit if setting level 8 */ public HGrid pointWrite(HRef id, int level, string who, HVal val, HNum dur) { HGridBuilder b = new HGridBuilder(); b.addCol("id"); b.addCol("level"); b.addCol("who"); b.addCol("val"); b.addCol("duration"); b.addRow(new HVal[] { id, HNum.make(level), HStr.make(who), val, dur }); HGrid req = b.toGrid(); HGrid res = call("pointWrite", req); return(res); }
public override HGrid sub(HRef[] ids, bool bChecked) { if (ids.Length == 0) { throw new ArgumentException("ids are empty", "ids"); } if (Closed) { throw new InvalidOperationException("watch is closed"); } // grid meta HGridBuilder b = new HGridBuilder(); if (ID != null) { b.Meta.add("watchId", ID); } if (Lease != null) { b.Meta.add("lease", Lease); } b.Meta.add("watchDis", dis()); // grid rows b.addCol("id"); for (int i = 0; i < ids.Length; ++i) { b.addRow(new HVal[] { ids[i] }); } // make request HGrid res; try { HGrid req = b.toGrid(); res = m_client.call("watchSub", req); } catch (CallErrException e) { // any server side error is considered close close(false); throw e; } // make sure watch is stored with its watch id if (ID == null) { ID = res.meta.getStr("watchId"); Lease = (HNum)res.meta.get("lease"); } // if checked, then check it if (bChecked) { if (res.numRows != ids.Length && ids.Length > 0) { throw new Exception("unknwon record " + ids[0]); } for (int i = 0; i < res.numRows; ++i) { if (res.row(i).missing("id")) { throw new Exception("unknwon record " + ids[i]); } } } return(res); }
private HGrid parseGrid() { bool nested = m_tokCur == HaystackToken.lt2; if (nested) { consume(HaystackToken.lt2); if (m_tokCur == HaystackToken.nl) { consume(HaystackToken.nl); } } bool bValisVer = false; if (m_curVal is string) { if (((string)m_curVal).CompareTo("ver") == 0) { bValisVer = true; } } // ver:"3.0" if (m_tokCur != HaystackToken.id || !bValisVer) { err("Expecting grid 'ver' identifier, not " + curToStr()); } consume(); consume(HaystackToken.colon); m_iversion = checkVersion(consumeStr()); // grid meta HGridBuilder gb = new HGridBuilder(); if (m_tokCur == HaystackToken.id) { gb.Meta.add(parseDict()); } consume(HaystackToken.nl); // column definitions int numCols = 0; while (m_tokCur == HaystackToken.id) { ++numCols; string name = consumeTagName(); HDict colMeta = HDict.Empty; if (m_tokCur == HaystackToken.id) { colMeta = parseDict(); } gb.addCol(name).add(colMeta); if (m_tokCur != HaystackToken.comma) { break; } consume(HaystackToken.comma); } if (numCols == 0) { err("No columns defined"); } consume(HaystackToken.nl); // grid rows while (true) { if (m_tokCur == HaystackToken.nl) { break; } if (m_tokCur == HaystackToken.eof) { break; } if (nested && m_tokCur == HaystackToken.gt2) { break; } // read cells HVal[] cells = new HVal[numCols]; for (int i = 0; i < numCols; ++i) { if (m_tokCur == HaystackToken.comma || m_tokCur == HaystackToken.nl || m_tokCur == HaystackToken.eof) { cells[i] = null; } else { cells[i] = parseVal(); } if (i + 1 < numCols) { consume(HaystackToken.comma); } } gb.addRow(cells); // newline or end if (nested && m_tokCur == HaystackToken.gt2) { break; } if (m_tokCur == HaystackToken.eof) { break; } consume(HaystackToken.nl); } if (m_tokCur == HaystackToken.nl) { consume(HaystackToken.nl); } if (nested) { consume(HaystackToken.gt2); } return(gb.toGrid()); }