示例#1
0
        private IMongoCollection <PumpEvent> GetCollection(HistoryDataTypeEnum historyDataType)
        {
            string collectionname = $"{eventCollectionName}{historyDataType.ToString()}";
            var    coll           = _db.GetCollection <PumpEvent>(collectionname);

            return(coll);
        }
示例#2
0
        private async Task StartReadHistoryByType(HistoryDataTypeEnum historytype, CancellationToken cancelToken)
        {
            await StartReadHistoryInfoAsync(historytype, cancelToken);
            await StartReadHistoryAsync(historytype, cancelToken);

            await StartReadHistoryEvents(cancelToken);
        }
示例#3
0
 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 };
 }
示例#4
0
        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);
        }
示例#5
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");
            }
        }
示例#6
0
 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);
 }
示例#7
0
        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;
            }
        }
示例#8
0
        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);
        }
示例#9
0
        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);
        }
示例#10
0
        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);
        }
示例#11
0
 public ReadHistoryInfoRequest(DateTime fromDateTime, HistoryDataTypeEnum historyDataType, byte[] offset) : this(fromDateTime.GetRtcBytes(offset).GetInt32(0), historyDataType)
 {
     this.FromDateTime = fromDateTime;
     this.FromRtc      = fromDateTime.GetRtcBytes(offset);
 }
示例#12
0
 public ReadHistoryRequest(int fromRtc, HistoryDataTypeEnum historyDataType) : base(fromRtc, historyDataType)
 {
 }
示例#13
0
 public ReadHistoryRequest(DateTime fromDateTime, HistoryDataTypeEnum historyDataType, byte[] offset) : base(fromDateTime, historyDataType, offset)
 {
 }