//****************************************************************************************************** // ActiveMeasurementsTableLookup.cs - Gbtc // // Copyright © 2016, Grid Protection Alliance. All Rights Reserved. // // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See // the NOTICE file distributed with this work for additional information regarding copyright ownership. // The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this // file except in compliance with the License. You may obtain a copy of the License at: // // http://opensource.org/licenses/MIT // // Unless agreed to in writing, the subject software distributed under the License is distributed on an // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the // License for the specific language governing permissions and limitations. // // Code Modification History: // ---------------------------------------------------------------------------------------------------- // 10/31/2016 - Steven E. Chisholm // Generated original version of source code. // //****************************************************************************************************** using System; using System.Collections.Generic; using System.Data; using GSF.Data; namespace GSF.TimeSeries.Data { /// /// Represents a table lookup for active measurements. /// public class ActiveMeasurementsTableLookup { private readonly Dictionary> m_lookupByDeviceID; private readonly Dictionary> m_lookupByDeviceNameNoStats; private readonly List m_emptySet; internal ActiveMeasurementsTableLookup(DataSet dataSet) { m_emptySet = new List(); m_lookupByDeviceID = new Dictionary>(); m_lookupByDeviceNameNoStats = new Dictionary>(StringComparer.CurrentCultureIgnoreCase); if (!dataSet.Tables.Contains("ActiveMeasurements")) return; DataTable table = dataSet.Tables["ActiveMeasurements"]; List rowList; foreach (DataRow row in table.Rows) { uint? id = row.AsUInt32("DeviceID"); if (id.HasValue) { if (!m_lookupByDeviceID.TryGetValue(id.Value, out rowList)) { rowList = new List(); m_lookupByDeviceID[id.Value] = rowList; } rowList.Add(row); } if (row.AsString("SignalType", string.Empty).Equals("STAT", StringComparison.CurrentCultureIgnoreCase)) continue; string device = row.AsString("Device"); if (device == null) continue; if (!m_lookupByDeviceNameNoStats.TryGetValue(device, out rowList)) { rowList = new List(); m_lookupByDeviceNameNoStats[device] = rowList; } rowList.Add(row); } } /// /// Gets all of the rows with the provided deviceID. /// Returns an empty set if the deviceID could not be found. /// /// the deviceID to lookup. /// /// Returns an empty set if the deviceID could not be found. /// public IEnumerable LookupByDeviceID(uint deviceId) => m_lookupByDeviceID.TryGetValue(deviceId, out List rows) ? rows : m_emptySet; /// /// Gets all of the rows with the provided device name. This will exclude /// all ActiveMeasurements that are classified as SignalType='STAT'. This is because /// 'STAT's are not associated with a device in the database. /// Returns an empty set if the deviceID could not be found. /// /// the device to lookup. /// /// Returns an empty set if the device could not be found. /// public IEnumerable LookupByDeviceNameNoStat(string deviceName) => m_lookupByDeviceNameNoStats.TryGetValue(deviceName, out List rows) ? rows : m_emptySet; } }