private void SetAutoCompletion() { var namesCollection = new AutoCompleteStringCollection(); namesCollection.AddRange(Treatments.Select(t => t.Name).ToArray()); SetAutoCompleteSourceForTextBox(txtTreatmentOldName, namesCollection); }
protected async override void AddTreatments(CancellationToken cancelToken) { if (this.Treatments.Count > 0) { try { await _client.AddTreatmentsAsync(this.Treatments, cancelToken); Logger.LogInformation($"Treatments uploaded to Nightscout. ({Treatments.Count})"); using (CgmUnitOfWork uow = new CgmUnitOfWork()) { uow.HistoryStatus.AddKeys(Treatments.Select(e => e.Key).ToList(), 0); } } catch (Exception) { throw; } } }
private async Task UploadElements(CancellationToken cancelToken) { if (Entries.Count > 0) { try { await _client.AddEntriesAsync(Entries, cancelToken); Logger.LogInformation($"Entries uploaded to Nightscout. ({Entries.Count})"); //log uploads using (CgmUnitOfWork uow = new CgmUnitOfWork()) { uow.HistoryStatus.AddKeys(Entries.Select(e => e.Key).ToList(), HistoryStatusTypeEnum.NightScout, 0); } } catch (Exception) { throw; } } if (this.Treatments.Count > 0) { try { await _client.AddTreatmentsAsync(this.Treatments, cancelToken); Logger.LogInformation($"Treatments uploaded to Nightscout. ({Treatments.Count})"); using (CgmUnitOfWork uow = new CgmUnitOfWork()) { uow.HistoryStatus.AddKeys(Treatments.Select(e => e.Key).ToList(), HistoryStatusTypeEnum.NightScout, 0); } } catch (Exception) { throw; } if (!string.IsNullOrEmpty(Session.Settings.NotificationUrl) && Session.Settings.OtherSettings.SendEventsToNotificationUrl) { var notif = this.Treatments.Where(e => !string.IsNullOrEmpty(e.Notification.Type)).Select(e => e.Notification); if (notif.Count() > 0) { NotificationClient client = new NotificationClient(Session.Settings.NotificationUrl); foreach (var item in notif) { await client.AddNotificationAsync(item, cancelToken); } Logger.LogInformation($"Notifications sent. ({notif.Count()})"); } } } if (this.DeviceStatus != null && !string.IsNullOrEmpty(this.DeviceStatus.Device)) { await _client.AddDeviceStatusAsync(new List <Nightscout.DeviceStatus>() { this.DeviceStatus }, cancelToken); Logger.LogInformation("DeviceStatus uploaded to Nightscout."); } //only upload new treatments //List<Treatment> treatments = new List<Treatment>(); //get trible ..... maybe this could be done better // var getCount = this.Treatments.Count * 3; //var all = await _client.TreatmentsAsync(null, getCount); //remove treatments that are uploaded. //var query = // from comp in this.Treatments // join entry in all on comp.EnteredBy equals entry.EnteredBy // select comp; //query.ToList().ForEach(e => this.Treatments.Remove(e)); //if (this.Treatments.Count > 0) //{ // await _client.AddTreatmentsAsync(this.Treatments, cancelToken); // Logger.LogInformation($"Treatments uploaded to Nightscout. ({Treatments.Count})"); // if (!string.IsNullOrEmpty(Session.Settings.NotificationUrl) && Session.Settings.OtherSettings.SendEventsToNotificationUrl) // { // var notif = this.Treatments.Where(e => !string.IsNullOrEmpty(e.Notification.Type)).Select(e => e.Notification); // if (notif.Count() > 0) // { // NotificationClient client = new NotificationClient(Session.Settings.NotificationUrl); // foreach (var item in notif) // { // await client.AddNotificationAsync(item, cancelToken); // } // Logger.LogInformation($"Notifications sent. ({notif.Count()})"); // } // } //} }