internal IList <string> ListSops(string studyInstanceUid, string seriesInstanceUid, string retrieveAe, string retrieveLocation, string mediaFileSetId, string mediaFileSetUid) { if (_dictionary.ContainsKey(studyInstanceUid)) { var seriesKey = new SeriesKey(seriesInstanceUid, retrieveAe, retrieveLocation, mediaFileSetId, mediaFileSetUid); if (_dictionary[studyInstanceUid].ContainsKey(seriesKey)) { return(_dictionary[studyInstanceUid][seriesKey].Keys.ToList()); } } return(new string[0]); }
private void CompactDictionary(string studyInstanceUid, SeriesKey seriesKey, Dictionary <string, string> sopDictionary, Dictionary <SeriesKey, Dictionary <string, string> > seriesDictionary) { // compacts the dictionary after having removed a single reference if (sopDictionary.Count == 0) { seriesDictionary.Remove(seriesKey); if (seriesDictionary.Count == 0) { _dictionary.Remove(studyInstanceUid); } } }
internal string GetSopClass(string studyInstanceUid, string seriesInstanceUid, string sopInstanceUid, string retrieveAe, string retrieveLocation, string mediaFileSetId, string mediaFileSetUid) { if (_dictionary.ContainsKey(studyInstanceUid)) { var seriesKey = new SeriesKey(seriesInstanceUid, retrieveAe, retrieveLocation, mediaFileSetId, mediaFileSetUid); if (_dictionary[studyInstanceUid].ContainsKey(seriesKey)) { string sopClass; if (_dictionary[studyInstanceUid][seriesKey].TryGetValue(sopInstanceUid, out sopClass)) { return(sopClass); } } } return(null); }
/// <summary> /// Checks whether or not the given SOP instance is referenced in the dictionary. /// </summary> /// <remarks> /// This overload checks for only the SOP instance reference that matches the specified origin (i.e. Retrieve AE Title, Retrive Location UID and Storage Media File-Set). /// </remarks> /// <param name="studyInstanceUid">The study instance UID.</param> /// <param name="seriesInstanceUid">The series instance UID.</param> /// <param name="sopClassUid">The SOP class UID.</param> /// <param name="sopInstanceUid">The SOP instance UID.</param> /// <param name="retrieveAeTitle">The DICOM AE from which the SOP instance can be retrieved over the network.</param> /// <param name="retrieveLocationUid">The UID of the location from which the SOP instance can be retrieved over the network</param> /// <param name="storageMediaFileSetId">The identifier of the storage media on which the SOP instance resides.</param> /// <param name="storageMediaFileSetUid">The UID of the storage media on which the SOP instance resides.</param> /// <exception cref="ArgumentNullException">Thrown if any of the arguments are null or empty.</exception> /// <returns>True if the SOP instance is referenced in the dictionary; False if a reference does not exist for the given SOP instance.</returns> public bool ContainsReference(string studyInstanceUid, string seriesInstanceUid, string sopClassUid, string sopInstanceUid, string retrieveAeTitle, string retrieveLocationUid, string storageMediaFileSetId, string storageMediaFileSetUid) { Dictionary <SeriesKey, Dictionary <string, string> > seriesDictionary; if (_dictionary.TryGetValue(studyInstanceUid, out seriesDictionary)) { Dictionary <string, string> sopDictionary; var seriesKey = new SeriesKey(seriesInstanceUid, retrieveAeTitle, retrieveLocationUid, storageMediaFileSetId, storageMediaFileSetUid); if (seriesDictionary.TryGetValue(seriesKey, out sopDictionary)) { string sopClass; return(sopDictionary.TryGetValue(sopInstanceUid, out sopClass) && sopClass == sopClassUid); } } return(false); }
public SeriesMap(DataSet dataSet) { ElementsOrder("SeriesKey", "Attributes", "Obs", "Annotations"); SeriesKey key = null; Map(o => o.Key).ToElement("SeriesKey", true) .Set(v => key = v) .ClassMap(() => new SeriesKeyMap(dataSet)); MapContainer(Namespaces.Generic + "Attributes", false) .MapCollection(o => GetKeyValues(o.Attributes)).ToElement("Value", false) .Set(v => dataSet.Attributes.Add(v.Concept, v.Value)) .ClassMap(() => new KeyValueMap());; MapCollection(o => o).ToElement("Obs", true) .Set(v => dataSet.Series[key].Add(v)) .ClassMap(() => new ObservationMap(dataSet)); }
/// <summary> /// Adds a SOP instance reference to the dictionary. /// </summary> /// <param name="studyInstanceUid">The study instance UID.</param> /// <param name="seriesInstanceUid">The series instance UID.</param> /// <param name="sopClassUid">The SOP class UID.</param> /// <param name="sopInstanceUid">The SOP instance UID.</param> /// <param name="retrieveAeTitle">Optional value specifying the DICOM AE from which the SOP instance can be retrieved over the network.</param> /// <param name="retrieveLocationUid">Optional value specifying the UID of the location from which the SOP instance can be retrieved over the network</param> /// <param name="storageMediaFileSetId">Optional value specifying the identifier of the storage media on which the SOP instance resides.</param> /// <param name="storageMediaFileSetUid">Optional value specifying the UID of the storage media on which the SOP instance resides.</param> /// <exception cref="ArgumentNullException">Thrown if any of the required arguments are null or empty.</exception> /// <returns>True if the SOP instance reference was added successfully; False if a reference already exists for the given SOP instance.</returns> public bool TryAddReference(string studyInstanceUid, string seriesInstanceUid, string sopClassUid, string sopInstanceUid, string retrieveAeTitle = null, string retrieveLocationUid = null, string storageMediaFileSetId = null, string storageMediaFileSetUid = null) { if (string.IsNullOrEmpty(studyInstanceUid)) { throw new ArgumentNullException("studyInstanceUid"); } if (string.IsNullOrEmpty(seriesInstanceUid)) { throw new ArgumentNullException("seriesInstanceUid"); } if (string.IsNullOrEmpty(sopClassUid)) { throw new ArgumentNullException("sopClassUid"); } if (string.IsNullOrEmpty(sopInstanceUid)) { throw new ArgumentNullException("sopInstanceUid"); } if (!_dictionary.ContainsKey(studyInstanceUid)) { _dictionary.Add(studyInstanceUid, new Dictionary <SeriesKey, Dictionary <string, string> >()); } var seriesDictionary = _dictionary[studyInstanceUid]; var seriesKey = new SeriesKey(seriesInstanceUid, retrieveAeTitle, retrieveLocationUid, storageMediaFileSetId, storageMediaFileSetUid); if (!seriesDictionary.ContainsKey(seriesKey)) { seriesDictionary.Add(seriesKey, new Dictionary <string, string>()); } var sopDictionary = seriesDictionary[seriesKey]; if (sopDictionary.ContainsKey(sopInstanceUid)) { return(false); } sopDictionary.Add(sopInstanceUid, sopClassUid); return(true); }
private Series GetSeriesInfo(Series timeDomainSeries, string channelDesignation, string measurementCharacteristicName) { string channelName; string measurementTypeName; string phaseName; string seriesTypeName; ChannelKey channelKey; SeriesKey seriesKey; channelName = string.Concat(timeDomainSeries.Channel.Name, " ", channelDesignation); measurementTypeName = timeDomainSeries.Channel.MeasurementType.Name; phaseName = timeDomainSeries.Channel.Phase.Name; seriesTypeName = timeDomainSeries.SeriesType.Name; channelKey = new ChannelKey(timeDomainSeries.Channel.LineID, 0, channelName, measurementTypeName, measurementCharacteristicName, phaseName); seriesKey = new SeriesKey(channelKey, seriesTypeName); return(GetSeriesInfo(timeDomainSeries.Channel.Meter, channelKey, seriesKey)); }
/// <summary> /// Attempts to remove the given SOP instance reference from the dictionary. /// </summary> /// <remarks> /// This overload removes only the SOP instance reference that matches the specified origin (i.e. Retrieve AE Title, Retrive Location UID and Storage Media File-Set). /// </remarks> /// <param name="studyInstanceUid">The study instance UID.</param> /// <param name="seriesInstanceUid">The series instance UID.</param> /// <param name="sopClassUid">The SOP class UID.</param> /// <param name="sopInstanceUid">The SOP instance UID.</param> /// <param name="retrieveAeTitle">The DICOM AE from which the SOP instance can be retrieved over the network.</param> /// <param name="retrieveLocationUid">The UID of the location from which the SOP instance can be retrieved over the network</param> /// <param name="storageMediaFileSetId">The identifier of the storage media on which the SOP instance resides.</param> /// <param name="storageMediaFileSetUid">The UID of the storage media on which the SOP instance resides.</param> /// <exception cref="ArgumentNullException">Thrown if any of the arguments are null or empty.</exception> /// <returns>True if the SOP instance reference was removed successfully; False if a reference does not exist for the given SOP instance.</returns> public bool TryRemoveReference(string studyInstanceUid, string seriesInstanceUid, string sopClassUid, string sopInstanceUid, string retrieveAeTitle, string retrieveLocationUid, string storageMediaFileSetId, string storageMediaFileSetUid) { if (string.IsNullOrEmpty(studyInstanceUid)) { throw new ArgumentNullException("studyInstanceUid"); } if (string.IsNullOrEmpty(seriesInstanceUid)) { throw new ArgumentNullException("seriesInstanceUid"); } if (string.IsNullOrEmpty(sopClassUid)) { throw new ArgumentNullException("sopClassUid"); } if (string.IsNullOrEmpty(sopInstanceUid)) { throw new ArgumentNullException("sopInstanceUid"); } if (_dictionary.ContainsKey(studyInstanceUid)) { var seriesKey = new SeriesKey(seriesInstanceUid, retrieveAeTitle, retrieveLocationUid, storageMediaFileSetId, storageMediaFileSetUid); var seriesDictionary = _dictionary[studyInstanceUid]; if (seriesDictionary.ContainsKey(seriesKey)) { var sopDictionary = seriesDictionary[seriesKey]; if (sopDictionary.ContainsKey(sopInstanceUid)) { if (sopDictionary[sopInstanceUid] == sopClassUid) { sopDictionary.Remove(sopInstanceUid); CompactDictionary(studyInstanceUid, seriesKey, sopDictionary, seriesDictionary); return(true); } } } } return(false); }
// Static Methods private static Series GetSeriesInfo(Meter meter, DataGroup dataGroup, string measurementTypeName, string phaseName) { int lineID = dataGroup.Line.ID; string measurementCharacteristicName = "Instantaneous"; string seriesTypeName = "Values"; char typeDesignation = (measurementTypeName == "Current") ? 'I' : measurementTypeName[0]; string phaseDesignation = (phaseName == "RES") ? "R" : phaseName.TrimEnd('N'); string channelName = string.Concat(typeDesignation, phaseDesignation); ChannelKey channelKey = new ChannelKey(lineID, 0, channelName, measurementTypeName, measurementCharacteristicName, phaseName); SeriesKey seriesKey = new SeriesKey(channelKey, seriesTypeName); Series dbSeries = meter.Channels .SelectMany(channel => channel.Series) .FirstOrDefault(series => seriesKey.Equals(new SeriesKey(series))); if ((object)dbSeries == null) { using (AdoDataConnection connection = meter.ConnectionFactory()) { Channel dbChannel = meter.Channels .FirstOrDefault(channel => channelKey.Equals(new ChannelKey(channel))); if ((object)dbChannel == null) { TableOperations <Channel> channelTable = new TableOperations <Channel>(connection); TableOperations <MeasurementType> measurementTypeTable = new TableOperations <MeasurementType>(connection); TableOperations <MeasurementCharacteristic> measurementCharacteristicTable = new TableOperations <MeasurementCharacteristic>(connection); TableOperations <Phase> phaseTable = new TableOperations <Phase>(connection); MeasurementType measurementType = measurementTypeTable.GetOrAdd(measurementTypeName); MeasurementCharacteristic measurementCharacteristic = measurementCharacteristicTable.GetOrAdd(measurementCharacteristicName); Phase phase = phaseTable.GetOrAdd(phaseName); dbChannel = new Channel() { MeterID = meter.ID, LineID = lineID, MeasurementTypeID = measurementType.ID, MeasurementCharacteristicID = measurementCharacteristic.ID, PhaseID = phase.ID, Name = channelKey.Name, SamplesPerHour = dataGroup.SamplesPerHour, Description = string.Concat(measurementCharacteristicName, " ", measurementTypeName, " ", phaseName), Enabled = true }; channelTable.AddNewRecord(dbChannel); dbChannel.ID = connection.ExecuteScalar <int>("SELECT @@IDENTITY"); meter.Channels = null; } TableOperations <Series> seriesTable = new TableOperations <Series>(connection); TableOperations <SeriesType> seriesTypeTable = new TableOperations <SeriesType>(connection); SeriesType seriesType = seriesTypeTable.GetOrAdd(seriesTypeName); dbSeries = new Series() { ChannelID = dbChannel.ID, SeriesTypeID = seriesType.ID, SourceIndexes = string.Empty }; seriesTable.AddNewRecord(dbSeries); dbSeries.ID = connection.ExecuteScalar <int>("SELECT @@IDENTITY"); dbChannel.Series = null; dbSeries = meter.Channels .SelectMany(channel => channel.Series) .First(series => seriesKey.Equals(new SeriesKey(series))); } } return(dbSeries); }
// Static Methods private static Series GetSeriesInfo(MeterInfoDataContext meterInfo, Meter meter, DataGroup dataGroup, string measurementTypeName, string phaseName) { int lineID; string measurementCharacteristicName; string seriesTypeName; char typeDesignation; char phaseDesignation; string channelName; DataContextLookup <ChannelKey, Channel> channelLookup; DataContextLookup <SeriesKey, Series> seriesLookup; DataContextLookup <string, MeasurementType> measurementTypeLookup; DataContextLookup <string, MeasurementCharacteristic> measurementCharacteristicLookup; DataContextLookup <string, Phase> phaseLookup; DataContextLookup <string, SeriesType> seriesTypeLookup; ChannelKey channelKey; SeriesKey seriesKey; lineID = dataGroup.Line.ID; measurementCharacteristicName = "Instantaneous"; seriesTypeName = "Values"; typeDesignation = (measurementTypeName == "Current") ? 'I' : measurementTypeName[0]; phaseDesignation = (phaseName == "RES") ? 'R' : phaseName[0]; channelName = string.Concat(typeDesignation, phaseDesignation); channelLookup = new DataContextLookup <ChannelKey, Channel>(meterInfo, channel => new ChannelKey(channel)) .WithFilterExpression(channel => channel.MeterID == meter.ID) .WithFilterExpression(channel => channel.LineID == dataGroup.Line.ID) .WithFilterExpression(channel => channel.MeasurementType.Name == measurementTypeName) .WithFilterExpression(channel => channel.MeasurementCharacteristic.Name == measurementCharacteristicName) .WithFilterExpression(channel => channel.Phase.Name == phaseName); seriesLookup = new DataContextLookup <SeriesKey, Series>(meterInfo, series => new SeriesKey(series)) .WithFilterExpression(series => series.Channel.Meter.ID == meter.ID) .WithFilterExpression(series => series.Channel.Line.ID == dataGroup.Line.ID) .WithFilterExpression(series => series.Channel.MeasurementType.Name == measurementTypeName) .WithFilterExpression(series => series.Channel.MeasurementCharacteristic.Name == measurementCharacteristicName) .WithFilterExpression(series => series.Channel.Phase.Name == phaseName) .WithFilterExpression(series => series.SeriesType.Name == seriesTypeName); measurementTypeLookup = new DataContextLookup <string, MeasurementType>(meterInfo, measurementType => measurementType.Name); measurementCharacteristicLookup = new DataContextLookup <string, MeasurementCharacteristic>(meterInfo, measurementCharacteristic => measurementCharacteristic.Name); phaseLookup = new DataContextLookup <string, Phase>(meterInfo, phase => phase.Name); seriesTypeLookup = new DataContextLookup <string, SeriesType>(meterInfo, seriesType => seriesType.Name); channelKey = new ChannelKey(lineID, 0, channelName, measurementTypeName, measurementCharacteristicName, phaseName); seriesKey = new SeriesKey(channelKey, seriesTypeName); return(seriesLookup.GetOrAdd(seriesKey, key => { SeriesType seriesType = seriesTypeLookup.GetOrAdd(key.SeriesType, name => new SeriesType() { Name = name, Description = name }); Channel channel = channelLookup.GetOrAdd(channelKey, chKey => { MeasurementType measurementType = measurementTypeLookup.GetOrAdd(chKey.MeasurementType, name => new MeasurementType() { Name = name, Description = name }); MeasurementCharacteristic measurementCharacteristic = measurementCharacteristicLookup.GetOrAdd(chKey.MeasurementCharacteristic, name => new MeasurementCharacteristic() { Name = name, Description = name }); Phase phase = phaseLookup.GetOrAdd(chKey.Phase, name => new Phase() { Name = name, Description = name }); return new Channel() { Meter = meter, Line = dataGroup.Line, MeasurementType = measurementType, MeasurementCharacteristic = measurementCharacteristic, Phase = phase, Name = chKey.Name, SamplesPerHour = dataGroup.SamplesPerHour, PerUnitValue = 0, HarmonicGroup = 0, Description = string.Concat(measurementCharacteristic.Name, " ", measurementType.Name, " ", phase.Name), Enabled = 1 }; }); return new Series() { SeriesType = seriesType, Channel = channel, SourceIndexes = string.Empty }; })); }
private void AddUndefinedChannels(MeterDataSet meterDataSet) { List <DataSeries> undefinedDataSeries = meterDataSet.DataSeries .Concat(meterDataSet.Digitals) .Where(dataSeries => (object)dataSeries.SeriesInfo.Channel.Line == null) .ToList(); if (undefinedDataSeries.Count <= 0) { return; } Meter meter = meterDataSet.Meter; if (meter.MeterLines.Count == 0) { Log.Warn($"Unable to automatically add channels to meter {meterDataSet.Meter.Name} because there are no lines associated with that meter."); return; } if (meter.MeterLines.Count > 1) { Log.Warn($"Unable to automatically add channels to meter {meterDataSet.Meter.Name} because there are too many lines associated with that meter."); return; } Line line = meter.MeterLines .Select(meterLine => meterLine.Line) .Single(); foreach (DataSeries series in undefinedDataSeries) { series.SeriesInfo.Channel.LineID = line.ID; } using (AdoDataConnection connection = meterDataSet.CreateDbConnection()) { TableOperations <MeasurementType> measurementTypeTable = new TableOperations <MeasurementType>(connection); TableOperations <MeasurementCharacteristic> measurementCharacteristicTable = new TableOperations <MeasurementCharacteristic>(connection); TableOperations <Phase> phaseTable = new TableOperations <Phase>(connection); TableOperations <SeriesType> seriesTypeTable = new TableOperations <SeriesType>(connection); Dictionary <string, MeasurementType> measurementTypeLookup = undefinedDataSeries .Select(dataSeries => dataSeries.SeriesInfo.Channel.MeasurementType) .DistinctBy(measurementType => measurementType.Name) .Select(measurementType => measurementTypeTable.GetOrAdd(measurementType.Name, measurementType.Description)) .ToDictionary(measurementType => measurementType.Name); Dictionary <string, MeasurementCharacteristic> measurementCharacteristicLookup = undefinedDataSeries .Select(dataSeries => dataSeries.SeriesInfo.Channel.MeasurementCharacteristic) .DistinctBy(measurementCharacteristic => measurementCharacteristic.Name) .Select(measurementCharacteristic => measurementCharacteristicTable.GetOrAdd(measurementCharacteristic.Name, measurementCharacteristic.Description)) .ToDictionary(measurementCharacteristic => measurementCharacteristic.Name); Dictionary <string, Phase> phaseLookup = undefinedDataSeries .Select(dataSeries => dataSeries.SeriesInfo.Channel.Phase) .DistinctBy(phase => phase.Name) .Select(phase => phaseTable.GetOrAdd(phase.Name, phase.Description)) .ToDictionary(phase => phase.Name); Dictionary <string, SeriesType> seriesTypeLookup = undefinedDataSeries .Select(dataSeries => dataSeries.SeriesInfo.SeriesType) .DistinctBy(seriesType => seriesType.Name) .Select(seriesType => seriesTypeTable.GetOrAdd(seriesType.Name, seriesType.Description)) .ToDictionary(seriesType => seriesType.Name); Dictionary <ChannelKey, Channel> channelLookup = meter.Channels .GroupBy(channel => new ChannelKey(channel)) .ToDictionary(grouping => { if (grouping.Count() > 1) { Log.Warn($"Detected duplicate channel key: {grouping.First().ID}"); } return(grouping.Key); }, grouping => grouping.First()); List <Channel> undefinedChannels = undefinedDataSeries .Select(dataSeries => dataSeries.SeriesInfo.Channel) .GroupBy(channel => new ChannelKey(channel)) .Where(grouping => !channelLookup.ContainsKey(grouping.Key)) .Select(grouping => grouping.First()) .ToList(); TableOperations <Channel> channelTable = new TableOperations <Channel>(connection); // Add all undefined channels to the database foreach (Channel channel in undefinedChannels) { string measurementTypeName = channel.MeasurementType.Name; string measurementCharacteristicName = channel.MeasurementCharacteristic.Name; string phaseName = channel.Phase.Name; channel.MeterID = meter.ID; channel.LineID = line.ID; channel.MeasurementTypeID = measurementTypeLookup[measurementTypeName].ID; channel.MeasurementCharacteristicID = measurementCharacteristicLookup[measurementCharacteristicName].ID; channel.PhaseID = phaseLookup[phaseName].ID; channel.Enabled = true; // If the per-unit value was not specified in the input file, // we can obtain the per-unit value from the line configuration // if the channel happens to be an instantaneous or RMS voltage if (!channel.PerUnitValue.HasValue) { if (IsVoltage(channel)) { if (IsLineToNeutral(channel)) { channel.PerUnitValue = (line.VoltageKV * 1000.0D) / Sqrt3; } else if (IsLineToLine(channel)) { channel.PerUnitValue = line.VoltageKV * 1000.0D; } } } channelTable.AddNewRecord(channel); } if (undefinedChannels.Count > 0) { // Refresh the channel lookup to // include all the new channels meter.Channels = null; channelLookup = meter.Channels .GroupBy(channel => new ChannelKey(channel)) .ToDictionary(grouping => grouping.Key, grouping => grouping.First()); } Dictionary <SeriesKey, Series> seriesLookup = meter.Channels .SelectMany(channel => channel.Series) .Where(series => series.SourceIndexes == "") .GroupBy(series => new SeriesKey(series)) .ToDictionary(grouping => { if (grouping.Count() > 1) { Log.Warn($"Detected duplicate series key: {grouping.First().ID}"); } return(grouping.Key); }, grouping => grouping.First()); List <Series> undefinedSeries = undefinedDataSeries .SelectMany(dataSeries => dataSeries.SeriesInfo.Channel.Series) .GroupBy(series => new SeriesKey(series)) .Where(grouping => !seriesLookup.ContainsKey(grouping.Key)) .Select(grouping => grouping.First()) .ToList(); TableOperations <Series> seriesTable = new TableOperations <Series>(connection); // Add all undefined series objects to the database foreach (Series series in undefinedSeries) { ChannelKey channelKey = new ChannelKey(series.Channel); string seriesTypeName = series.SeriesType.Name; series.ChannelID = channelLookup[channelKey].ID; series.SeriesTypeID = seriesTypeLookup[seriesTypeName].ID; series.SourceIndexes = ""; seriesTable.AddNewRecord(series); } if (undefinedSeries.Count > 0) { // Refresh the series lookup to // include all the new series foreach (Channel channel in meter.Channels) { channel.Series = null; } seriesLookup = meter.Channels .SelectMany(channel => channel.Series) .GroupBy(series => new SeriesKey(series)) .ToDictionary(grouping => grouping.Key, grouping => grouping.First()); } // Update all undefined data series to reference the new database objects foreach (DataSeries dataSeries in undefinedDataSeries) { SeriesKey seriesKey = new SeriesKey(dataSeries.SeriesInfo); Series series = seriesLookup[seriesKey]; dataSeries.SeriesInfo = series; } } }
// Static Methods private static Series GetSeriesInfo(Meter meter, DataGroup dataGroup, string measurementTypeName, string phaseName, int assetID) { string measurementCharacteristicName = "Instantaneous"; string seriesTypeName = "Values"; char typeDesignation = (measurementTypeName == "Current") ? 'I' : measurementTypeName[0]; string phaseDesignation = (phaseName == "RES") ? "R" : phaseName.TrimEnd('N'); string channelName = string.Concat(typeDesignation, phaseDesignation); ChannelKey channelKey = new ChannelKey(assetID, 0, channelName, measurementTypeName, measurementCharacteristicName, phaseName); SeriesKey seriesKey = new SeriesKey(channelKey, seriesTypeName); Series dbSeries = meter.Channels .SelectMany(channel => channel.Series) .FirstOrDefault(series => seriesKey.Equals(new SeriesKey(series))); if ((object)dbSeries == null) { Channel dbChannel = meter.Channels .FirstOrDefault(channel => channelKey.Equals(new ChannelKey(channel))); //need to get Asset based on the asset of the datagroup or the connected assets Asset asset = dataGroup.Asset; if (asset.ID != assetID) { List <Asset> connectedAssets = asset.ConnectedAssets.ToList(); asset = connectedAssets.Find(item => item.ID == assetID); } if ((object)dbChannel == null) { MeasurementType measurementType = new MeasurementType() { Name = measurementTypeName }; MeasurementCharacteristic measurementCharacteristic = new MeasurementCharacteristic() { Name = measurementCharacteristicName }; Phase phase = new Phase() { Name = phaseName }; dbChannel = new Channel() { MeterID = meter.ID, AssetID = assetID, MeasurementTypeID = measurementType.ID, MeasurementCharacteristicID = measurementCharacteristic.ID, PhaseID = phase.ID, Name = channelKey.Name, SamplesPerHour = dataGroup.SamplesPerHour, Description = string.Concat(measurementCharacteristicName, " ", measurementTypeName, " ", phaseName), Enabled = true, Meter = meter, Asset = asset, MeasurementType = measurementType, MeasurementCharacteristic = measurementCharacteristic, Phase = phase, Series = new List <Series>() }; meter.Channels.Add(dbChannel); } SeriesType seriesType = new SeriesType() { Name = seriesTypeName }; dbSeries = new Series() { ChannelID = dbChannel.ID, SeriesTypeID = seriesType.ID, SourceIndexes = string.Empty, Channel = dbChannel, SeriesType = seriesType }; dbChannel.Series.Add(dbSeries); } return(dbSeries); }
// Static Methods private static Series GetSeriesInfo(MeterInfoDataContext meterInfo, Meter meter, DataGroup dataGroup, string measurementTypeName, string phaseName) { int lineID; string measurementCharacteristicName; string seriesTypeName; char typeDesignation; char phaseDesignation; string channelName; DataContextLookup<ChannelKey, Channel> channelLookup; DataContextLookup<SeriesKey, Series> seriesLookup; DataContextLookup<string, MeasurementType> measurementTypeLookup; DataContextLookup<string, MeasurementCharacteristic> measurementCharacteristicLookup; DataContextLookup<string, Phase> phaseLookup; DataContextLookup<string, SeriesType> seriesTypeLookup; ChannelKey channelKey; SeriesKey seriesKey; lineID = dataGroup.Line.ID; measurementCharacteristicName = "Instantaneous"; seriesTypeName = "Values"; typeDesignation = (measurementTypeName == "Current") ? 'I' : measurementTypeName[0]; phaseDesignation = (phaseName == "RES") ? 'R' : phaseName[0]; channelName = string.Concat(typeDesignation, phaseDesignation); channelLookup = new DataContextLookup<ChannelKey, Channel>(meterInfo, channel => new ChannelKey(channel)) .WithFilterExpression(channel => channel.MeterID == meter.ID) .WithFilterExpression(channel => channel.LineID == dataGroup.Line.ID); seriesLookup = new DataContextLookup<SeriesKey, Series>(meterInfo, series => new SeriesKey(series)) .WithFilterExpression(series => series.Channel.Meter.ID == meter.ID) .WithFilterExpression(series => series.Channel.Line.ID == dataGroup.Line.ID); measurementTypeLookup = new DataContextLookup<string, MeasurementType>(meterInfo, measurementType => measurementType.Name); measurementCharacteristicLookup = new DataContextLookup<string, MeasurementCharacteristic>(meterInfo, measurementCharacteristic => measurementCharacteristic.Name); phaseLookup = new DataContextLookup<string, Phase>(meterInfo, phase => phase.Name); seriesTypeLookup = new DataContextLookup<string, SeriesType>(meterInfo, seriesType => seriesType.Name); channelKey = new ChannelKey(lineID, 0, channelName, measurementTypeName, measurementCharacteristicName, phaseName); seriesKey = new SeriesKey(channelKey, seriesTypeName); return seriesLookup.GetOrAdd(seriesKey, key => { SeriesType seriesType = seriesTypeLookup.GetOrAdd(key.SeriesType, name => new SeriesType() { Name = name, Description = name }); Channel channel = channelLookup.GetOrAdd(channelKey, chKey => { MeasurementType measurementType = measurementTypeLookup.GetOrAdd(chKey.MeasurementType, name => new MeasurementType() { Name = name, Description = name }); MeasurementCharacteristic measurementCharacteristic = measurementCharacteristicLookup.GetOrAdd(chKey.MeasurementCharacteristic, name => new MeasurementCharacteristic() { Name = name, Description = name }); Phase phase = phaseLookup.GetOrAdd(chKey.Phase, name => new Phase() { Name = name, Description = name }); return new Channel() { Meter = meter, Line = dataGroup.Line, MeasurementType = measurementType, MeasurementCharacteristic = measurementCharacteristic, Phase = phase, Name = chKey.Name, SamplesPerHour = dataGroup.SamplesPerHour, PerUnitValue = 0, HarmonicGroup = 0, Description = string.Concat(measurementCharacteristic.Name, " ", measurementType.Name, " ", phase.Name), Enabled = 1 }; }); return new Series() { SeriesType = seriesType, Channel = channel, SourceIndexes = string.Empty }; }); }
internal string GetSopClass(string studyInstanceUid, string seriesInstanceUid, string sopInstanceUid, string retrieveAe, string retrieveLocation, string mediaFileSetId, string mediaFileSetUid) { if (_dictionary.ContainsKey(studyInstanceUid)) { var seriesKey = new SeriesKey(seriesInstanceUid, retrieveAe, retrieveLocation, mediaFileSetId, mediaFileSetUid); if (_dictionary[studyInstanceUid].ContainsKey(seriesKey)) { string sopClass; if (_dictionary[studyInstanceUid][seriesKey].TryGetValue(sopInstanceUid, out sopClass)) return sopClass; } } return null; }
internal IList<string> ListSops(string studyInstanceUid, string seriesInstanceUid, string retrieveAe, string retrieveLocation, string mediaFileSetId, string mediaFileSetUid) { if (_dictionary.ContainsKey(studyInstanceUid)) { var seriesKey = new SeriesKey(seriesInstanceUid, retrieveAe, retrieveLocation, mediaFileSetId, mediaFileSetUid); if (_dictionary[studyInstanceUid].ContainsKey(seriesKey)) return _dictionary[studyInstanceUid][seriesKey].Keys.ToList(); } return new string[0]; }
private Series GetSeriesInfo(Meter meter, ChannelKey channelKey, SeriesKey seriesKey) { Series dbSeries = meter.Channels .SelectMany(channel => channel.Series) .FirstOrDefault(series => seriesKey.Equals(new SeriesKey(series))); if ((object)dbSeries == null) { using (AdoDataConnection connection = meter.ConnectionFactory()) { Channel dbChannel = meter.Channels .FirstOrDefault(channel => channelKey.Equals(new ChannelKey(channel))); if ((object)dbChannel == null) { TableOperations <Channel> channelTable = new TableOperations <Channel>(connection); TableOperations <MeasurementType> measurementTypeTable = new TableOperations <MeasurementType>(connection); TableOperations <MeasurementCharacteristic> measurementCharacteristicTable = new TableOperations <MeasurementCharacteristic>(connection); TableOperations <Phase> phaseTable = new TableOperations <Phase>(connection); MeasurementType measurementType = measurementTypeTable.GetOrAdd(channelKey.MeasurementType); MeasurementCharacteristic measurementCharacteristic = measurementCharacteristicTable.GetOrAdd(channelKey.MeasurementCharacteristic); Phase phase = phaseTable.GetOrAdd(channelKey.Phase); dbChannel = new Channel() { MeterID = meter.ID, LineID = channelKey.LineID, MeasurementTypeID = measurementType.ID, MeasurementCharacteristicID = measurementCharacteristic.ID, PhaseID = phase.ID, Name = channelKey.Name, SamplesPerHour = 0, Description = string.Concat(channelKey.MeasurementCharacteristic, " ", channelKey.MeasurementType, " ", channelKey.Phase), Enabled = true }; channelTable.AddNewRecord(dbChannel); dbChannel.ID = connection.ExecuteScalar <int>("SELECT @@IDENTITY"); meter.Channels = null; } TableOperations <Series> seriesTable = new TableOperations <Series>(connection); TableOperations <SeriesType> seriesTypeTable = new TableOperations <SeriesType>(connection); SeriesType seriesType = seriesTypeTable.GetOrAdd(seriesKey.SeriesType); dbSeries = new Series() { ChannelID = dbChannel.ID, SeriesTypeID = seriesType.ID, SourceIndexes = string.Empty }; seriesTable.AddNewRecord(dbSeries); dbSeries.ID = connection.ExecuteScalar <int>("SELECT @@IDENTITY"); dbChannel.Series = null; dbSeries = meter.Channels .SelectMany(channel => channel.Series) .First(series => seriesKey.Equals(new SeriesKey(series))); } } return(dbSeries); }