///////////////////////////////////////////////////////////////////i/////// // Utils ////////////////////////////////////////////////////////////////////////// void verifyGrid(string str, HDict meta, object[] cols, HVal[][] rows) { /* * System.out.println(); * System.out.println("###############################################"); * System.out.println(); * System.out.println(str); */ // normalize nulls if (meta == null) { meta = HDict.Empty; } for (int i = 0; i < cols.Length; ++i) { if (cols[i] == null) { cols[i] = HDict.Empty; } } // read from zinc HGrid grid = new HZincReader(str).readGrid(); verifyGridEq(grid, meta, cols, rows); // write grid and verify we can parse that too string writeStr = HZincWriter.gridToString(grid); HGrid writeGrid = new HZincReader(writeStr).readGrid(); verifyGridEq(writeGrid, meta, cols, rows); }
public void readGrid_withTagDef() { var reader = new HZincReader( @"ver:""3.0"" id,def,doc,mod @p:struktonLibrary:r:25b81501-75003ad2 ""struktonActivePointOnly"",^struktonActivePointOnly,""Import only active points"",2020-01-20T07:36:33.162Z"); var grid = reader.readGrid(); Assert.IsTrue(grid.row(0).get("def") is HDef); }
/** * Parse from string using the given timezone as context for * date based ranges. The formats are: * - "today" * - "yesterday" * - "{date}" * - "{date},{date}" * - "{dateTime},{dateTime}" * - "{dateTime}" // anything after given timestamp * Throw ParseException is invalid string format. */ public static HDateTimeRange make(string str, HTimeZone tz) { // handle keywords str = str.Trim(); if (str.CompareTo("today") == 0) { return(make(HDate.today(), tz)); } if (str.CompareTo("yesterday") == 0) { return(make(HDate.today().minusDays(1), tz)); } // parse scalars int comma = str.IndexOf(','); HVal start = null, end = null; if (comma < 0) { start = new HZincReader(str).readVal(); } else { start = new HZincReader(str.Substring(0, comma)).readVal(); end = new HZincReader(str.Substring(comma + 1)).readVal(); } // figure out what we parsed for start,end if (start is HDate) { if (end == null) { return(make((HDate)start, tz)); } if (end is HDate) { return(make((HDate)start, (HDate)end, tz)); } } else if (start is HDateTime) { if (end == null) { return(make((HDateTime)start, HDateTime.now(tz))); } if (end is HDateTime) { return(make((HDateTime)start, (HDateTime)end)); } } throw new FormatException("Invalid HDateTimeRange: " + str); }
/** * 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); }
/** * 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); }