public void RemoveSubscribedMeasurements(ICollection <Guid> measurementIDs) { ObservableCollection <int> deviceIDsForMeasurementsToBeAdded = new ObservableCollection <int>(); ObservableCollection <DataModelMeasurement> measurementsToBeRemoved; //If All Devices is not selected on the screen and a specific device is selected then we will just initialize that device. //Otherwise, maintain a list of unique device ids for which measurements are being subscribed and initialize all of them. if (CurrentDevice.Key > 0) { deviceIDsForMeasurementsToBeAdded.Add(CurrentDevice.Key); } if (measurementIDs != null && measurementIDs.Count > 0) { Mouse.OverrideCursor = Cursors.Wait; AdoDataConnection database = new AdoDataConnection(CommonFunctions.DefaultSettingsCategory); try { measurementsToBeRemoved = DataModelMeasurement.LoadFromKeys(database, measurementIDs.ToList()); foreach (DataModelMeasurement measurement in measurementsToBeRemoved) { measurement.Subscribed = false; DataModelMeasurement.Save(database, measurement); if (CurrentDevice.Key == 0 && measurement.DeviceID != null) { if (!deviceIDsForMeasurementsToBeAdded.Contains((int)measurement.DeviceID)) { deviceIDsForMeasurementsToBeAdded.Add((int)measurement.DeviceID); } } } if (SubscriptionChanged != null) { SubscriptionChanged(this, null); } if (deviceIDsForMeasurementsToBeAdded.Count > 0) { ThreadPool.QueueUserWorkItem(InitializeDeviceConnection, deviceIDsForMeasurementsToBeAdded); } } catch (Exception ex) { Popup("ERROR: " + ex.Message, "Unsubscribe Measurements", MessageBoxImage.Error); } finally { if (database != null) { database.Dispose(); } Mouse.OverrideCursor = null; } } }
private void ButtonAddMore_Click(object sender, RoutedEventArgs e) { IEnumerable <Measurement> selectedMeasurements; ObservableCollection <Measurement> addedMeasurements; // Determine which of the selected measurements have been added to the output stream measurements selectedMeasurements = Measurement.LoadFromKeys(null, MeasurementPager.SelectedMeasurements.ToList()); addedMeasurements = new ObservableCollection <Measurement>(selectedMeasurements); // Add measurements to output stream measurements OutputStreamMeasurement.AddMeasurements(null, m_outputStreamID, addedMeasurements); m_dataContext = new OutputStreamMeasurements(m_outputStreamID, 23); this.DataContext = m_dataContext; PopupAddMore.IsOpen = false; }