/// <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)); }
/// <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)); }
/// <summary> /// Read a dictionary of tags. /// </summary> public HaystackDictionary ReadDictionary() { var dictionary = new HaystackDictionary(); bool braces = _currentToken == HaystackToken.lbrace; if (braces) { Consume(HaystackToken.lbrace); } while (_currentToken == HaystackToken.id) { // tag name string id = ConsumeTagName(); if (!char.IsLower(id[0])) { throw GetException("Invalid dict tag name: " + id); } // tag value HaystackValue val = HaystackMarker.Instance; if (_currentToken == HaystackToken.colon) { Consume(HaystackToken.colon); val = ParseValue(); } dictionary.Add(id, val); } if (braces) { Consume(HaystackToken.rbrace); } return(dictionary); }
public void WriteEntity_DateTime_CorrectKind() { using (var writer = new StringWriter()) using (var jsonWriter = new JsonTextWriter(writer) { Formatting = Formatting.Indented }) { // Arrange. var haysonWriter = new HaysonWriter(jsonWriter); var entity = new HaystackDictionary(); entity.Add("ts", new HaystackDateTime(new DateTime(2020, 1, 1), HaystackTimeZone.UTC)); // Act. haysonWriter.WriteEntity(entity); var hayson = writer.ToString(); // Assert. var target = @"{ ""ts"": { ""_kind"": ""dateTime"", ""val"": ""2020-01-01T00:00:00.0000000+00:00"", ""tz"": ""UTC"" } }"; Assert.AreEqual(target.Replace("\r", ""), hayson.Replace("\r", "")); } }
public void TestAdd() { HaystackDictionary dict = new HaystackDictionary().AddMarker("x").AddMarker("y"); dict.Add("z", new HaystackString("z")); Assert.AreEqual(3, dict.Count); Assert.AreEqual(new HaystackMarker(), dict["x"]); Assert.AreEqual(new HaystackMarker(), dict["y"]); Assert.AreEqual(new HaystackString("z"), dict["z"]); }
public void TestBasics() { var tags = new HaystackDictionary(); tags.Add("id", new HaystackReference("aaaa-bbbb")); tags.Add("site", new HaystackMarker()); tags.Add("geoAddr", new HaystackString("Richmond, Va")); tags.Add("area", new HaystackNumber(1200, "ft")); tags.Add("date", new HaystackDate(2000, 12, 3)); tags.Add("null", null); // size Assert.AreEqual(5, tags.Count); Assert.IsFalse(tags.IsEmpty()); // configured tags Assert.IsTrue(tags.Get("id").Equals(new HaystackReference("aaaa-bbbb"))); Assert.IsTrue(tags.Get("site").Equals(new HaystackMarker())); Assert.IsTrue(tags.Get("geoAddr").Equals(new HaystackString("Richmond, Va"))); Assert.IsTrue(tags.Get("area").Equals(new HaystackNumber(1200, "ft"))); Assert.IsTrue(tags.Get("date").Equals(new HaystackDate(2000, 12, 3))); Assert.ThrowsException <HaystackUnknownNameException>(() => tags.Get("null")); // missing tag Assert.IsFalse(tags.ContainsKey("foo")); Assert.ThrowsException <HaystackUnknownNameException>(() => tags.Get("foo")); }
public void TestEquality() { var a = new HaystackDictionary(); a.Add("x", new HaystackMarker()); Assert.IsTrue(a.Equals(new HaystackDictionary().AddMarker("x"))); Assert.IsFalse(a.Equals(new HaystackDictionary().AddNumber("x", 3))); Assert.IsFalse(a.Equals(new HaystackDictionary().AddMarker("y"))); Assert.IsFalse(a.Equals(new HaystackDictionary().AddMarker("x").AddMarker("y"))); a = new HaystackDictionary().AddMarker("x").AddString("y", "str"); Assert.IsTrue(a.Equals(new HaystackDictionary().AddMarker("x").AddString("y", "str"))); Assert.IsTrue(a.Equals(new HaystackDictionary().AddString("y", "str").AddMarker("x"))); Assert.IsFalse(a.Equals(new HaystackDictionary().AddString("x", "str").AddString("y", "str"))); Assert.IsFalse(a.Equals(new HaystackDictionary().AddMarker("x").AddString("y", "strx"))); Assert.IsFalse(a.Equals(new HaystackDictionary().AddString("y", "str"))); Assert.IsFalse(a.Equals(new HaystackDictionary().AddMarker("x"))); Assert.IsFalse(a.Equals(new HaystackDictionary().AddMarker("x").AddString("yy", "str"))); a = new HaystackDictionary().AddValue("x", null); Assert.IsTrue(a.Equals(new HaystackDictionary().AddValue("x", null))); Assert.IsTrue(a.Equals(new HaystackDictionary().AddValue("foo", null).AddValue("bar", null))); Assert.IsTrue(a.Equals(new HaystackDictionary())); }