示例#1
0
        // 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);
        }
示例#2
0
        // 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
                };
            }));
        }
示例#3
0
        private void AddUndefinedChannels(MeterDataSet meterDataSet)
        {
            DataContextLookup <SeriesKey, Series>                 seriesLookup;
            DataContextLookup <ChannelKey, Channel>               channelLookup;
            DataContextLookup <string, MeasurementType>           measurementTypeLookup;
            DataContextLookup <string, MeasurementCharacteristic> measurementCharacteristicLookup;
            DataContextLookup <string, SeriesType>                seriesTypeLookup;
            DataContextLookup <string, Phase> phaseLookup;

            List <DataSeries> undefinedDataSeries;

            Line line;

            undefinedDataSeries = meterDataSet.DataSeries
                                  .Where(dataSeries => (object)dataSeries.SeriesInfo.Channel.Line == null)
                                  .ToList();

            if (undefinedDataSeries.Count <= 0)
            {
                return;
            }

            line = meterDataSet.Meter.MeterLines
                   .Select(meterLine => meterLine.Line)
                   .Single();

            foreach (DataSeries series in undefinedDataSeries)
            {
                series.SeriesInfo.Channel.LineID = line.ID;
            }

            seriesLookup = new DataContextLookup <SeriesKey, Series>(m_meterInfo, GetSeriesKey)
                           .WithFilterExpression(series => series.Channel.MeterID == meterDataSet.Meter.ID)
                           .WithFilterExpression(series => series.SourceIndexes == "");

            channelLookup = new DataContextLookup <ChannelKey, Channel>(m_meterInfo, GetChannelKey)
                            .WithFilterExpression(channel => channel.MeterID == meterDataSet.Meter.ID);

            measurementTypeLookup           = new DataContextLookup <string, MeasurementType>(m_meterInfo, type => type.Name);
            measurementCharacteristicLookup = new DataContextLookup <string, MeasurementCharacteristic>(m_meterInfo, characteristic => characteristic.Name);
            seriesTypeLookup = new DataContextLookup <string, SeriesType>(m_meterInfo, type => type.Name);
            phaseLookup      = new DataContextLookup <string, Phase>(m_meterInfo, phase => phase.Name);

            for (int i = 0; i < undefinedDataSeries.Count; i++)
            {
                DataSeries dataSeries = undefinedDataSeries[i];

                // Search for an existing series info object
                dataSeries.SeriesInfo = seriesLookup.GetOrAdd(GetSeriesKey(dataSeries.SeriesInfo), seriesKey =>
                {
                    Series clonedSeries = dataSeries.SeriesInfo.Clone();

                    // Search for an existing series type object to associate with the new series
                    SeriesType seriesType = seriesTypeLookup.GetOrAdd(dataSeries.SeriesInfo.SeriesType.Name, name => dataSeries.SeriesInfo.SeriesType.Clone());

                    // Search for an existing channel object to associate with the new series
                    Channel channel = channelLookup.GetOrAdd(GetChannelKey(dataSeries.SeriesInfo.Channel), channelKey =>
                    {
                        Channel clonedChannel = dataSeries.SeriesInfo.Channel.Clone();

                        // Search for an existing measurement type object to associate with the new channel
                        MeasurementType measurementType = measurementTypeLookup.GetOrAdd(dataSeries.SeriesInfo.Channel.MeasurementType.Name, name => dataSeries.SeriesInfo.Channel.MeasurementType.Clone());

                        // Search for an existing measurement characteristic object to associate with the new channel
                        MeasurementCharacteristic measurementCharacteristic = measurementCharacteristicLookup.GetOrAdd(dataSeries.SeriesInfo.Channel.MeasurementCharacteristic.Name, name => dataSeries.SeriesInfo.Channel.MeasurementCharacteristic.Clone());

                        // Search for an existing phase object to associate with the new channel
                        Phase phase = phaseLookup.GetOrAdd(dataSeries.SeriesInfo.Channel.Phase.Name, name => dataSeries.SeriesInfo.Channel.Phase.Clone());

                        // Assign the foreign keys of the channel
                        // to reference the objects from the lookup
                        clonedChannel.Meter                     = meterDataSet.Meter;
                        clonedChannel.Line                      = line;
                        clonedChannel.MeasurementType           = measurementType;
                        clonedChannel.MeasurementCharacteristic = measurementCharacteristic;
                        clonedChannel.Phase                     = phase;
                        clonedChannel.Enabled                   = 1;

                        // 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 (!clonedChannel.PerUnitValue.HasValue)
                        {
                            if (IsVoltage(clonedChannel))
                            {
                                if (IsLineToNeutral(clonedChannel))
                                {
                                    clonedChannel.PerUnitValue = (line.VoltageKV * 1000.0D) / Sqrt3;
                                }
                                else if (IsLineToLine(clonedChannel))
                                {
                                    clonedChannel.PerUnitValue = line.VoltageKV * 1000.0D;
                                }
                            }
                        }

                        return(clonedChannel);
                    });

                    // Assign the foreign keys of the series
                    // to reference the objects from the lookup
                    clonedSeries.SeriesType = seriesType;
                    clonedSeries.Channel    = channel;

                    return(clonedSeries);
                });
            }
        }
示例#4
0
        // 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);
        }
示例#5
0
        private static Series GetSeriesInfo(MeterInfoDataContext meterInfo, Meter meter, DataGroup dataGroup, int index)
        {
            Dictionary <int, string> measurementTypeNameLookup = new Dictionary <int, string>()
            {
                { VAIndex, "Voltage" },
                { VBIndex, "Voltage" },
                { VCIndex, "Voltage" },
                { IAIndex, "Current" },
                { IBIndex, "Current" },
                { ICIndex, "Current" },
                { IRIndex, "Current" }
            };

            Dictionary <int, string> phaseNameLookup = new Dictionary <int, string>()
            {
                { VAIndex, "AN" },
                { VBIndex, "BN" },
                { VCIndex, "CN" },
                { IAIndex, "AN" },
                { IBIndex, "BN" },
                { ICIndex, "CN" },
                { IRIndex, "RES" }
            };

            int    lineID;
            string measurementTypeName;
            string measurementCharacteristicName;
            string phaseName;
            string seriesTypeName;
            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;

            SeriesKey  seriesKey;
            ChannelKey channelKey;

            lineID = dataGroup.Line.ID;
            measurementTypeName           = measurementTypeNameLookup[index];
            measurementCharacteristicName = "Instantaneous";
            phaseName      = phaseNameLookup[index];
            seriesTypeName = "Values";
            channelName    = string.Concat(measurementTypeName, " ", phaseName);

            channelLookup = new DataContextLookup <ChannelKey, Channel>(meterInfo, GetChannelKey)
                            .WithFilterExpression(channel => channel.MeterID == meter.ID)
                            .WithFilterExpression(channel => channel.LineID == dataGroup.Line.ID);

            seriesLookup = new DataContextLookup <SeriesKey, Series>(meterInfo, GetSeriesKey)
                           .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);

            seriesKey  = Tuple.Create(lineID, 0, channelName, measurementTypeName, measurementCharacteristicName, phaseName, seriesTypeName);
            channelKey = Tuple.Create(lineID, 0, channelName, measurementTypeName, measurementCharacteristicName, phaseName);

            return(seriesLookup.GetOrAdd(seriesKey, key =>
            {
                SeriesType seriesType = seriesTypeLookup.GetOrAdd(seriesTypeName, name => new SeriesType()
                {
                    Name = name, Description = name
                });

                Channel channel = channelLookup.GetOrAdd(channelKey, chKey =>
                {
                    MeasurementType measurementType = measurementTypeLookup.GetOrAdd(measurementTypeName, name => new MeasurementType()
                    {
                        Name = name, Description = name
                    });
                    MeasurementCharacteristic measurementCharacteristic = measurementCharacteristicLookup.GetOrAdd(measurementCharacteristicName, name => new MeasurementCharacteristic()
                    {
                        Name = name, Description = name
                    });
                    Phase phase = phaseLookup.GetOrAdd(phaseName, name => new Phase()
                    {
                        Name = name, Description = name
                    });

                    return new Channel()
                    {
                        Meter = meter,
                        Line = dataGroup.Line,
                        MeasurementType = measurementType,
                        MeasurementCharacteristic = measurementCharacteristic,
                        Phase = phase,
                        Name = string.Concat(measurementType.Name, " ", phase.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
                };
            }));
        }
示例#6
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);
        }