public async Task Do()
        {
            var client = new GaloreClient(new GaloreConnector());

            var assets = await client.GetAssets("/fleet", null, 1);

            var fleet = assets.First();

            foreach (var edge in fleet.Edges)
            {
                var childNode = edge.Node;
            }

            // Get all timeseries nodes under ship
            var shipTimeseriesNodes = await client.GetAssets("/fleet/ship_apples", "TimeSeries");

            // Warning: should probably not do this :)
            var allTimeseriesNodes = await client.GetAssets(null, "TimeSeries");

            // Fetch latest datapoint for specific timeseries ID
            var lastDataForId = await client.GetLatestTimeseries("123");

            // Get latest data for all specified timeseries ID's
            var latestTimeseriesDataForIds = await client.GetLatestTimeseriesForIds(shipTimeseriesNodes.Select(x => x.TimeseriesId).ToArray());
        }
示例#2
0
        static async Task Demo()
        {
            try
            {
                Console.WriteLine("- - - - - - - Galore API V2 Demo - - - - - - -");

                var client = new GaloreClient(new GaloreConnector());

                Console.Write("Fetching fleet...");
                var fleet = await client.GetAssetByPath("/Fleet", 1);

                Console.Write(" Success!\n");
                Console.WriteLine(FormatNode(fleet));

                Console.WriteLine($"\n{fleet.Name} edges:");
                foreach (var edge in fleet.Edges)
                {
                    Console.WriteLine($"\tName: {edge.Name} ID: {edge.Node.Id}");
                }

                Console.Write("\nFetching ship by ID...");
                var shipEdge = fleet.Edges.Find(x => x.Name.Equals("Ship_Apples", StringComparison.OrdinalIgnoreCase));
                if (shipEdge == null)
                {
                    Console.Write(" Failed.");
                    return;
                }
                var ship = await client.GetAssetById(shipEdge.Node.Id, 1);

                Console.Write(" Success!\n");

                var engines = ship.Edges.Find(x => x.Name.Equals("Engines", StringComparison.OrdinalIgnoreCase));
                if (engines == null)
                {
                    Console.WriteLine("Found no engines.. Are you sure this is not a row boat?");
                    return;
                }
                var timeseriesNodes = await client.GetAssets(path : engines.Node.Path, nodeType : "TimeSeries");

                Console.Write($"Fetching latest data for all timeseries nodes under path {engines.Node.Path}");
                var timeseriesIds = timeseriesNodes
                                    .Select(x =>
                {
                    // Bug workaround
                    // Bug 105472: AssetModel API timeseries ID is empty if the node contains an empty streamLink attribute
                    return(string.IsNullOrEmpty(x.TimeseriesId)
                            ? x.Id
                            : x.TimeseriesId);
                }).ToArray();
                var latestDataForNodes = await client.GetLatestTimeseriesForIds(timeseriesIds);

                Console.Write(" Success!\n");
                Console.WriteLine("\nLatest data for nodes:");
                foreach (var(key, value) in latestDataForNodes)
                {
                    if (string.IsNullOrEmpty(value.Error))
                    {
                        Console.WriteLine($"\t{key}: {value.DataPoint}");
                    }
                    else
                    {
                        Console.WriteLine($"\t{key}: {value.Error}");
                    }
                }

                var tsNode = timeseriesNodes.Find(x => x.Name.Equals("Total_Power", StringComparison.OrdinalIgnoreCase));
                Console.WriteLine($"\nFetching data from last year for node {tsNode.Path}");

                var from         = DateTime.Now.AddYears(-1);
                var to           = DateTime.Now;
                var timeseriesId = string.IsNullOrEmpty(tsNode !.TimeseriesId)
                    ? tsNode !.Id
                    : tsNode !.TimeseriesId;
                var data = await client.GetTimeseriesData(timeseriesId, from, to);

                Console.WriteLine();
                PrintData(data, 15);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: {0}", ex.Message);
            }
        }