/// <summary> /// Return the current status of a point's priority array. /// The resulting grid has the following columns: /// - level: number [1-17] (17 is default) /// - levelDis: Human description of level /// - val: current value at level or null /// - who: who last controlled the value at this level /// </summary> /// <param name="id">Reference of a writable point.</param> /// <returns>Result grid.</returns> public Task <HaystackGrid> PointWriteArrayAsync(HaystackReference id) { var req = new HaystackGrid() .AddColumn("id") .AddRow(id); return(CallAsync("pointWrite", req)); }
/// <summary> /// Write a set of history time-series data to a given point record. /// The record must already exist and tagged as a historized point. /// The timestamp timezone must exactly match the point's timezone "tz" tag. /// </summary> /// <param name="id">Record ID.</param> /// <param name="items">Time-series data.</param> /// <param name="metaData">Optional metadata to include.</param> public Task <HaystackGrid> HisWriteAsync(HaystackReference id, HaystackHistoryItem[] items, HaystackDictionary metaData = null) { var meta = metaData ?? new HaystackDictionary(); meta.Add("id", id); HaystackGrid req = new HaystackGrid(items, meta); return(CallAsync("hisWrite", req)); }
/// <summary> /// Read history time-series data for a given point record and time range. /// The range has an inclusive start and an exclusive end. /// The range must match the timezone configured on the history record. /// The range will use the timezone of the record. /// </summary> /// <param name="id">Record ID.</param> /// <param name="range">Time range.</param> /// <returns>Grid of time-series data.</returns> public Task <HaystackGrid> HisReadAsync(HaystackReference id, string range) { var req = new HaystackGrid() .AddColumn("id") .AddColumn("range") .AddRow(id, new HaystackString(range)); return(CallAsync("hisRead", req)); }
/// <summary> /// Read history time-series data for a given record and time range. /// The range has an inclusive start and an exclusive end. /// The range must match the timezone configured on the history record. /// </summary> /// <param name="id">Record ID.</param> /// <param name="range">Time range.</param> /// <returns>Grid of time-series data.</returns> public Task <HaystackGrid> HisReadAsync(HaystackReference id, HaystackDateTimeRange range) { var req = new HaystackGrid() .AddColumn("id") .AddColumn("range") .AddRow(id, new HaystackString($"{ZincWriter.ToZinc(range.Start)},{ZincWriter.ToZinc(range.End)}")); return(CallAsync("hisRead", req)); }
/// <summary> /// Invoke an action using the "invokeAction" call. /// </summary> /// <param name="id">Target to invoke the action on.</param> /// <param name="action">Action to invoke.</param> /// <param name="args">Action arguments.</param> /// <returns>Action result grid.</returns> public Task <HaystackGrid> InvokeActionAsync(HaystackReference id, string action, HaystackDictionary args) { var meta = new HaystackDictionary(); meta.Add("id", id); meta.Add("action", new HaystackString(action)); var req = new HaystackGrid(new[] { args }, meta); return(CallAsync("invokeAction", req)); }
private HaystackValue ParseLiteral() { object val = _currentValue; if (_currentToken == HaystackToken.@ref && _peekToken == HaystackToken.str) { val = new HaystackReference(((HaystackReference)val).Value, ((HaystackString)_peekValue).Value); Consume(HaystackToken.@ref); } Consume(); return((HaystackValue)val); }
/// <summary> /// Write to a given level of a writable point, and return the current status /// of a writable point's priority array <see cref="pointWriteArray"/>. /// </summary> /// <param name="id">Reference of a writable point.</param> /// <param name="level">Number for level to write [1-17].</param> /// <param name="who">Username performing the write, defaults to user dis.</param> /// <param name="val">Value to write or null to auto the level.</param> /// <param name="dur">Number with duration unit if setting level 8.</param> /// <returns>Result grid.</returns> public Task <HaystackGrid> PointWriteAsync(HaystackReference id, int level, string who, HaystackValue val, HaystackNumber dur) { var req = new HaystackGrid() .AddColumn("id") .AddColumn("level") .AddColumn("who") .AddColumn("val") .AddColumn("duration") .AddRow(id, new HaystackNumber(level), new HaystackString(who), val, dur); return(CallAsync("pointWrite", req)); }
public void TestBasics() { var hrefTest = new HaystackReference("a"); var str = new HaystackString("string"); List <HaystackValue> items = new List <HaystackValue>(); items.Add(hrefTest); items.Add(str); var list = new HaystackList(items); Assert.AreEqual(list.Count, 2); Assert.AreEqual(list[0], hrefTest); Assert.AreEqual(list[1], str); }
/// <summary> /// Read a single record by its unique ID. /// Throws an exception if the record was not found. /// </summary> /// <param name="id">Record ID.</param> /// <returns>Matching record.</returns> public async Task <HaystackDictionary> ReadByIdAsync(HaystackReference id) { HaystackGrid res = await ReadByIdsAsync(new HaystackReference[] { id }); if (res.IsEmpty()) { throw new Exception($"Record not found for: {id}"); } HaystackDictionary rec = res.Row(0); if (!rec.ContainsKey("id")) { throw new Exception($"Record not found for: {id}"); } return(rec); }
/// <summary> /// Convenience method to call HisWriteNoWarnAsync with a "noWarn" marker to /// prevent warnings when writing out-of-order data. /// <param name="id">Record ID.</param> /// <param name="items">Time-series data.</param> public static Task <HaystackGrid> HisWriteNoWarnAsync(this IHaystackClient client, HaystackReference id, HaystackHistoryItem[] items) { var meta = new HaystackDictionary(); meta.Add("noWarn", new HaystackMarker()); return(client.HisWriteAsync(id, items, meta)); }