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); }
void verifyGridEq(HGrid grid, HDict meta, Object[] cols, HVal[][] rows) { // meta Assert.IsTrue(grid.meta.hequals(meta)); // cols Assert.AreEqual(grid.numCols, cols.Length / 2); for (int i = 0; i < grid.numCols; ++i) { Assert.AreEqual(grid.col(i).Name, cols[i * 2 + 0]); Assert.IsTrue(grid.col(i).meta.hequals(cols[i * 2 + 1])); } // rows Assert.AreEqual(grid.numRows, rows.Length); for (int ri = 0; ri < rows.Length; ++ri) { HVal[] expected = rows[ri]; HRow actual = grid.row(ri); for (int ci = 0; ci < expected.Length; ++ci) { Assert.AreEqual(expected[ci], actual.get(grid.col(ci).Name, false)); } } }
private async Task <HGrid> PostGridAsync(string op, HGrid req, string mimeType) { string reqStr = HZincWriter.gridToString(req); string resStr = await PostStringAsync(op, reqStr, mimeType); return(new HZincReader(resStr).readGrid()); }
// 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)); }
/** * 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 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; } }
// Depart from Java - This has a method where mimetype selection can be specified - NOTE: This toolkit // does not yet support a JsonReader private HGrid postGrid(string op, HGrid req, string mimeType) { string reqStr = HZincWriter.gridToString(req); string resStr = postString(uri + op, reqStr, mimeType); return(new HZincReader(resStr).readGrid()); }
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")); }
private void writeNestedGrid(HGrid grid) { p("<<").nl(); writeGrid(grid); p(">>"); flush(); }
////////////////////////////////////////////////////////////////////////// // HGridWriter ////////////////////////////////////////////////////////////////////////// // Write a grid public override void writeGrid(HGrid grid) { // meta p("ver:\"").p(m_iVersion).p(".0\"").writeMeta(grid.meta).nl(); // cols if (grid.numCols == 0) { // technically this shoudl be illegal, but // for robustness handle it here throw new ArgumentException("Grid has no cols", "grid"); } else { for (int i = 0; i < grid.numCols; ++i) { if (i > 0) { p(','); } writeCol(grid.col(i)); } } nl(); // rows for (int i = 0; i < grid.numRows; ++i) { writeRow(grid, grid.row(i)); nl(); } flush(); }
HCol verifyCol(HGrid g, int i, string n) { HCol col = g.col(i); Assert.IsTrue(g.col(i).hequals(g.col(n))); Assert.AreEqual(col.Name, n); return(col); }
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)); }
public HGrid call(string op, HGrid req) { HGrid res = postGrid(op, req); if (res.isErr()) { throw new CallErrException(res); } return(res); }
void verifyGridIterator(HGrid g) { int c = 0; while (c < g.numRows) { c++; } Assert.AreEqual(g.numRows, c); }
////////////////////////////////////////////////////////////////////////// // Call ////////////////////////////////////////////////////////////////////////// /** * Make a call to the given operation. The request grid is posted * to the URI "this.uri+op" and the response is parsed as a grid. * Raise CallNetworkException if there is a communication I/O error. * Raise CallErrException if there is a server side error and an error * grid is returned. */ public async Task <HGrid> CallAsync(string op, HGrid req, string mimeType) { HGrid res = await PostGridAsync(op, req, mimeType); if (res.isErr()) { throw new CallErrException(res); } return(res); }
private static string Msg(HGrid grid) { HVal dis = grid.meta.get("dis", false); if (dis is HStr) { return(((HStr)dis).Value); } return("server side error"); }
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)); }
////////////////////////////////////////////////////////////////////////// // Utils ////////////////////////////////////////////////////////////////////////// // Write a grid to an in-memory a string public static string gridToString(HGrid grid) { MemoryStream ms = new MemoryStream(); StreamWriter swOut = new StreamWriter(ms); new HJsonWriter(swOut).writeGrid(grid); StreamReader sr = new StreamReader(ms); ms.Position = 0; return(sr.ReadToEnd()); }
private void writeRow(HGrid grid, HRow row) { for (int i = 0; i < grid.numCols; ++i) { HVal val = row.get(grid.col(i), false); if (i > 0) { m_swOut.Write(m_cDelimiter); } writeCell(valToString(val)); } }
/** * 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); }
////////////////////////////////////////////////////////////////////////// // 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); }
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")); }
/** * Query one entity record that matches the given filter. If * there is more than one record, then it is undefined which one is * returned. If there are no matches than return null or raise * UnknownRecException based on checked flag. * NOTE: Was final */ public async Task <HDict> readAsync(string filter, bool bChecked) { HGrid grid = await readAllAsync(filter, 1); if (grid.numRows > 0) { return(grid.row(0)); } if (bChecked) { throw new Exception("rec not found for: " + filter); } return(null); }
/** * Read a list of entity records by their unique identifier. * Return a grid where each row of the grid maps to the respective * id array (indexes line up). If checked is true and any one of the * ids cannot be resolved then raise UnknownRecException for first id * not resolved. If checked is false, then each id not found has a * row where every cell is null. * NOTE: Was final */ public HGrid readByIds(HRef[] ids, bool bChecked) { HGrid grid = readByIds(ids); if (bChecked) { for (int i = 0; i < grid.numRows; ++i) { if (grid.row(i).missing("id")) { throw new Exception("rec not found for: " + ids[i].ToString()); } } } return(grid); }
////////////////////////////////////////////////////////////////////////// // Reads ////////////////////////////////////////////////////////////////////////// protected override HDict onReadById(HRef id) { HGrid res = readByIds(new HRef[] { id }, false); if (res.isEmpty()) { return(null); } HDict rec = res.row(0); if (rec.missing("id")) { return(null); } return(rec); }
/** * Call "evalAll" operation to evaluate a batch of vendor specific * expressions on the server. See "eval" method for list of vendor * expression formats. The request grid must specify an "expr" column. * A separate grid is returned for each row in the request. If checked * is false, then this call does *not* automatically check for error * grids. Client code must individual check each grid for partial * failures using "Grid.isErr". If checked is true and one of the * requests failed, then raise CallErrException for first failure. */ public async Task <HGrid[]> EvalAllAsync(HGrid req, bool bChecked) { string reqStr = HZincWriter.gridToString(req); string resStr = await PostStringAsync("evalAll", reqStr, "text/zinc"); HGrid[] res = new HZincReader(resStr).readGrids(); if (bChecked) { for (int i = 0; i < res.Length; ++i) { if (res[i].isErr()) { throw new CallErrException(res[i]); } } } return(res); }
/** * Call "evalAll" operation to evaluate a batch of vendor specific * expressions on the server. See "eval" method for list of vendor * expression formats. The request grid must specify an "expr" column. * A separate grid is returned for each row in the request. If checked * is false, then this call does *not* automatically check for error * grids. Client code must individual check each grid for partial * failures using "Grid.isErr". If checked is true and one of the * requests failed, then raise CallErrException for first failure. */ public HGrid[] evalAll(HGrid req, bool bChecked) { string reqStr = HZincWriter.gridToString(req); string resStr = postString(uri + "evalAll", reqStr); HGrid[] res = new HZincReader(resStr).readGrids(); if (bChecked) { for (int i = 0; i < res.Length; ++i) { if (res[i].isErr()) { throw new CallErrException(res[i]); } } } return(res); }