Ejemplo n.º 1
0
        public async Task <IEnumerable <MachineValue> > LastMachineValuesAsync(string machineName)
        {
            var query = $"SELECT * FROM machinedata WHERE machinename='{machineName}' GROUP BY * ORDER BY DESC LIMIT 1";
            var data  = await _influxDb.QueryAsync("machinedata", query);

            var row = data.FirstOrDefault();

            if (row == null)
            {
                return(null);
            }

            var res = new List <MachineValue>();

            for (var i = 1; i < row.Columns.Length; i++)
            {
                res.Add(new MachineValue
                {
                    Name      = row.Columns[i],
                    Value     = row.Values[0][i],
                    TimeStamp = (DateTime)row.Values[0][0]
                });
            }

            return(res);
        }
Ejemplo n.º 2
0
        public async void Query_DB_Test()
        {
            string dbName = GetNewDbName();

            InfluxDbApiCreateResponse createResponse = await _db.CreateDatabaseAsync(dbName);

            const string TmpSerieName = "testSeries";
            Serie        serie        = new Serie.Builder(TmpSerieName)
                                        .Columns("value1", "value2")
                                        .Values(DateTime.Now.Millisecond, 5)
                                        .Build();
            InfluxDbApiResponse writeResponse = await _db.WriteAsync(dbName, TimeUnit.Milliseconds, serie);

            List <Serie> series =
                await _db.QueryAsync(dbName, string.Format("select * from {0}", TmpSerieName), TimeUnit.Milliseconds);

            InfluxDbApiDeleteResponse deleteResponse = await _db.DeleteDatabaseAsync(dbName);

            series.Should().NotBeNull();
            series.Count.Should().Be(1);

            createResponse.Success.Should().BeTrue();
            writeResponse.Success.Should().BeTrue();
            deleteResponse.Success.Should().BeTrue();
        }
Ejemplo n.º 3
0
        public void DbQuery_OnInvalidQuery_ShouldThrowException()
        {
            Func <Task> act = async() => { await _influx.QueryAsync(_dbName, "blah"); };

            act.ShouldThrow <InfluxDbApiException>();
        }