private static void TestBlueprints(M2XClient m2x) { Console.WriteLine("Testing blueprints..."); var blueprints = m2x.GetBlueprints(); Console.WriteLine("Number of blueprints = " + blueprints.blueprints.Count); var blueprintName = "test-" + Guid.NewGuid(); var blueprintData = m2x.CreateBlueprint(blueprintName, M2XVisibility.Public, "description"); Console.WriteLine("New blueprint created - id = " + blueprintData.id); var key = blueprintData.key; M2XBlueprint blueprint = m2x.GetBlueprint(blueprintData.id); Console.WriteLine("Blueprint name = " + blueprint.Details().name); blueprint.Update(blueprintName + "updated", M2XVisibility.Public); Console.WriteLine("Blueprint updated"); blueprint.Delete(); Console.WriteLine("Blueprint deleted"); DeleteKey(m2x, key); }
private static void TestFeeds(M2XClient m2x) { Console.WriteLine("Testing feeds..."); var feeds = m2x.GetFeeds(); Console.WriteLine("Number of feeds = " + feeds.feeds.Count); feeds = m2x.GetFeeds(type: M2XFeedType.Blueprint); Console.WriteLine("Number of blueprint feeds = " + feeds.feeds.Count); var dsName = "test feed - " + Guid.NewGuid(); var dsData = m2x.CreateBlueprint(dsName, M2XVisibility.Public, "test feed"); Console.WriteLine("New blueprint feed created - id = " + dsData.id); var key = dsData.key; M2XBlueprint ds = m2x.GetBlueprint(dsData.id); M2XFeed feed = ds.GetFeed(); Console.WriteLine("Feed name = " + feed.Details().name); feed.UpdateLocation(-37.9788423562422, -57.5478776916862, "test location", 500); Console.WriteLine("Feed location updated"); var location = feed.GetLocation(); Console.WriteLine("Feed location obtained. latitude = " + location.latitude + "; longitude = " + location.longitude + "; elevation = " + location.elevation); var s1 = feed.GetStream("test1"); var s2 = feed.GetStream("test2"); var s3 = feed.GetStream("test3"); s1.CreateOrUpdate(new { unit = new { label = "random1", symbol = "R1" } }); Console.WriteLine("Stream with name = test1 created."); s2.CreateOrUpdate(new { unit = new { label = "random2", symbol = "R2" } }); Console.WriteLine("Stream with name = test2 created."); s3.CreateOrUpdate(new { unit = new { label = "random3", symbol = "R3" } }); Console.WriteLine("Stream with name = test3 created."); Console.WriteLine("Number of streams = " + feed.GetStreams().streams.Count); Console.WriteLine("Started posting values to all three streams. Go ahead and check your feed on Web UI - https://m2x.att.com/blueprints. Press any key to break."); var r = new Random(1000); while (!Console.KeyAvailable) { s1.PostValues(new[] { new M2XPostedValue { At = DateTime.UtcNow, Value = r.Next(100).ToString() } }); s2.PostValues(new[] { new M2XPostedValue { At = DateTime.UtcNow, Value = r.Next(500).ToString() } }); s3.PostValues(new[] { new M2XPostedValue { At = DateTime.UtcNow, Value = r.Next(1000).ToString() } }); Thread.Sleep(1000); } Console.WriteLine("Number of values in stream test1 = " + s1.GetValues().values.Count); s1.Delete(); Console.WriteLine("Number of values in stream test2 = " + s2.GetValues().values.Count); s2.Delete(); Console.WriteLine("Number of values in stream test3 = " + s3.GetValues().values.Count); s3.Delete(); Console.WriteLine("Data streams deleted"); Console.WriteLine("Number of streams = " + feed.GetStreams().streams.Count); Console.WriteLine("Number of records in log = " + feed.Log().requests.Count); ds.Delete(); Console.WriteLine("Blueprint feed deleted"); DeleteKey(m2x, key); }