//public List<int> GetTankMeasuresUniqueIDs() //{ // try // { // return tankMeasuresCollection.Distinct<int>("tankID", new BsonDocument()).ToList().OrderBy(x => x).ToList(); // } // catch (Exception e) // { // return new List<int>(); // } //} public List <TankMeasure> GetLatestTankMeasures(int amount) { try { return(tankMeasuresCollection.Aggregate().SortByDescending((a) => a["date"]).Limit(amount) .ToList().Select(x => TankMeasure.Parse(x)).ToList()); } catch (Exception e) { return(null); } }
public List <TankMeasure> GetLatestTankMeasuresByTime(int hours) { try { return(tankMeasuresCollection.Aggregate().SortByDescending((a) => a["date"]).ToList() .FindAll(x => (getTime() - DateTime.Parse(x["date"].AsString)).TotalHours <= hours) .ToList().Select(x => TankMeasure.Parse(x)).ToList()); } catch (Exception e) { return(null); } }
private void ReadDataTankMeasures(int amount) { for (int i = 0; i < amount; i++) { if (!tankMeasuresFile.EndOfStream) { waitingTankMeasures.Add(TankMeasure.Parse(tankMeasuresFile.ReadLine())); } else { return; } } }
public TankMeasure GetLatestTankMeasure(int tankID) { try { BsonDocument filter = new BsonDocument() { { "tankID", tankID } }; Task <BsonDocument> result = tankMeasuresCollection.Find(filter).SortByDescending((a) => a["date"]).FirstAsync(); return(TankMeasure.Parse(result.Result)); } catch (Exception e) { return(null); } }
//--Public_Interface_Save------------------------------------// public async void AddTankMeasure(TankMeasure data) { await tankMeasuresCollection.InsertOneAsync(TankMeasure.Parse(data)); }