private IMongoCollection <PumpEvent> GetCollection(HistoryDataTypeEnum historyDataType) { string collectionname = $"{eventCollectionName}{historyDataType.ToString()}"; var coll = _db.GetCollection <PumpEvent>(collectionname); return(coll); }
private async Task StartReadHistoryByType(HistoryDataTypeEnum historytype, CancellationToken cancelToken) { await StartReadHistoryInfoAsync(historytype, cancelToken); await StartReadHistoryAsync(historytype, cancelToken); await StartReadHistoryEvents(cancelToken); }
public ReadHistoryInfoRequest(int fromRtc, HistoryDataTypeEnum historyDataType) { this.FromRtc = BitConverter.GetBytes(fromRtc); this.HistoryDataTypeRaw = (byte)historyDataType; this.HistoryReading = 0x04; // full history = 0x03, partial history = 0x04 this.Unknown3 = new byte[] { 0x00, 0x00 }; this.ToRtc = new byte[] { 0xff, 0xff, 0xff, 0xff }; }
public int GetSize(HistoryDataTypeEnum historyDataType) { var handler = MultiPacketHandlers.FirstOrDefault(e => e.ReadInfoResponse.HistoryDataType == (HistoryDataTypeEnum)historyDataType);// MultiPacketHandlers.FirstOrDefault(e => e.ReadInfoResponse.HistoryDataType == (HistoryDataTypeEnum)historyDataType); if (handler != null) { return(handler.ReadInfoResponse.HistorySize); } return(0); }
private async Task StartReadHistoryInfoAsync(HistoryDataTypeEnum historytype, CancellationToken cancelToken) { Logger.LogInformation($"ReadHistoryInfo: {historytype.ToString()}"); await StartCommunicationStandardResponse(Session.GetReadHistoryInfo(historytype), cancelToken); if (Session.PumpDataHistory.MultiPacketHandlers.Count(e => e.ReadInfoResponse.HistoryDataType == historytype) == 0) { throw new Exception("Error reading historyInfo"); } }
public AstmStart GetReadHistory(HistoryDataTypeEnum historyDataType, int expectedSize) { if (this.PumpTime != null && this.PumpTime.OffSet.Length == 4) { int lastRtc = GetLastRtc(historyDataType); AstmStart msg = GetPumpEnvelope(AstmSendMessageType.READ_HISTORY_REQUEST); ((PumpEnvelope)((MedtronicMessage2)msg.Message2).Message).Message.Message = new ReadHistoryRequest(lastRtc, historyDataType); return(msg); } return(null); }
private void InsertPumpEvent(List <PumpEvent> events, HistoryDataTypeEnum historyDataType) { var coll = GetCollection(historyDataType); try { // coll.UpdateMany( filter, events, new UpdateOptions { IsUpsert = true }); coll.InsertMany(events); } catch (Exception ex) { throw; } }
private int GetLastRtc(HistoryDataTypeEnum historyDataType) { var lastRead = this.Settings.LastRead.FirstOrDefault(e => e.DataType == (int)historyDataType); int lastRtc = 0; if (lastRead == null) { lastRtc = DateTime.Now.AddDays(-1 * this.Settings.HistoryDaysBack).GetRtcBytes(this.PumpTime.OffSet).GetInt32(0); } else { lastRtc = lastRead.LastRtc; } return(lastRtc); }
private async Task StartReadHistoryAsync(HistoryDataTypeEnum historytype, CancellationToken cancelToken) { Logger.LogInformation($"ReadHistory: {historytype.ToString()}"); int expectedSize = this.Session.PumpDataHistory.GetSize(historytype); CommunicationBlock communicationBlock = new CommunicationBlock(); communicationBlock.Request = Session.GetReadHistory(historytype, expectedSize); communicationBlock.ExpectedResponses.Add(new SendMessageResponsePattern()); communicationBlock.ExpectedResponses.Add(new RecieveMessageResponsePattern()); communicationBlock.ExpectedResponses.Add(new RecieveMessageResponsePattern()); communicationBlock.ExpectedResponses.Add(new RecieveMessageResponsePattern()); await StartCommunication(communicationBlock, cancelToken); }
public AstmStart GetReadHistoryInfo(HistoryDataTypeEnum historyDataType) { try { if (this.PumpTime != null && this.PumpTime.OffSet.Length == 4) { int lastRtc = GetLastRtc(historyDataType); Logger.LogInformation($"Getting history for {historyDataType.ToString()} from {this.PumpTime.GetDateTime(BitConverter.GetBytes(lastRtc)).ToString()}"); AstmStart msg = GetPumpEnvelope(AstmSendMessageType.READ_HISTORY_INFO_REQUEST); ((PumpEnvelope)((MedtronicMessage2)msg.Message2).Message).Message.Message = new ReadHistoryInfoRequest(lastRtc, historyDataType); return(msg); } } catch (Exception) { throw; } return(null); }
public ReadHistoryInfoRequest(DateTime fromDateTime, HistoryDataTypeEnum historyDataType, byte[] offset) : this(fromDateTime.GetRtcBytes(offset).GetInt32(0), historyDataType) { this.FromDateTime = fromDateTime; this.FromRtc = fromDateTime.GetRtcBytes(offset); }
public ReadHistoryRequest(int fromRtc, HistoryDataTypeEnum historyDataType) : base(fromRtc, historyDataType) { }
public ReadHistoryRequest(DateTime fromDateTime, HistoryDataTypeEnum historyDataType, byte[] offset) : base(fromDateTime, historyDataType, offset) { }