Ejemplo n.º 1
0
        private void LoadRangeLimits(MeterDataSet meterDataSet)
        {
            Dictionary <Channel, List <TrendingDataSummaryResource.TrendingDataSummary> > trendingDataSummaries;

            AlarmData.AlarmRangeLimitDataTable rangeLimitTable;

            Channel channel;

            trendingDataSummaries = meterDataSet.GetResource <TrendingDataSummaryResource>().TrendingDataSummaries;

            rangeLimitTable = new AlarmData.AlarmRangeLimitDataTable();

            foreach (KeyValuePair <Channel, List <TrendingDataSummaryResource.TrendingDataSummary> > summaries in trendingDataSummaries)
            {
                channel = summaries.Key;

                InitializeRangeLimitTable(rangeLimitTable, channel);

                // Update alarm log for each excursion
                foreach (TrendingDataSummaryResource.TrendingDataSummary summary in summaries.Value)
                {
                    foreach (AlarmData.AlarmRangeLimitRow rangeLimit in rangeLimitTable.Where(row => row.Enabled != 0))
                    {
                        CheckAlarm(channel, summary, rangeLimit);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void InitializeRangeLimitTable(AlarmData.AlarmRangeLimitDataTable rangeLimitTable, Channel channel)
        {
            AlarmRangeLimitTableAdapter        rangeLimitAdapter;
            DefaultAlarmRangeLimitTableAdapter defaultRangeLimitAdapter;

            AlarmData.DefaultAlarmRangeLimitDataTable defaultRangeLimitTable;
            AlarmData.AlarmRangeLimitRow alarmRangeLimitRow;

            // Clear existing rows from the range limit table
            rangeLimitTable.Clear();

            // Fill the range limit table with range limits for the given channel
            rangeLimitAdapter = m_dbAdapterContainer.GetAdapter <AlarmRangeLimitTableAdapter>();
            rangeLimitAdapter.FillBy(rangeLimitTable, channel.ID);

            // If limits exist for the given channel,
            // range limit table has been successfully initialized
            if (rangeLimitTable.Count != 0)
            {
                return;
            }

            // Get the default range limits for the measurement type and characteristic of this channel
            defaultRangeLimitAdapter = m_dbAdapterContainer.GetAdapter <DefaultAlarmRangeLimitTableAdapter>();
            defaultRangeLimitTable   = defaultRangeLimitAdapter.GetDataBy(channel.MeasurementTypeID, channel.MeasurementCharacteristicID);

            // If there are no default limits for the channel,
            // then the range limit table has been successfully initialized
            if (defaultRangeLimitTable.Count == 0)
            {
                return;
            }

            lock (RangeLimitLock)
            {
                // Fill the range limit table one more time inside the lock to
                // ensure that no other threads have written limits for this channel
                rangeLimitAdapter.FillBy(rangeLimitTable, channel.ID);

                // If there are still no limits defined for this channel,
                // update the table to include this channel's default limits
                if (rangeLimitTable.Count == 0)
                {
                    foreach (AlarmData.DefaultAlarmRangeLimitRow row in defaultRangeLimitTable)
                    {
                        alarmRangeLimitRow = rangeLimitTable.NewAlarmRangeLimitRow();

                        alarmRangeLimitRow.ChannelID      = channel.ID;
                        alarmRangeLimitRow.AlarmTypeID    = row.AlarmTypeID;
                        alarmRangeLimitRow.Severity       = row.Severity;
                        alarmRangeLimitRow.RangeInclusive = row.RangeInclusive;
                        alarmRangeLimitRow.PerUnit        = row.PerUnit;
                        alarmRangeLimitRow.Enabled        = 1;

                        if (!row.IsHighNull())
                        {
                            alarmRangeLimitRow.High = row.High;
                        }

                        if (!row.IsLowNull())
                        {
                            alarmRangeLimitRow.Low = row.Low;
                        }

                        rangeLimitTable.AddAlarmRangeLimitRow(alarmRangeLimitRow);
                    }

                    using (SqlBulkCopy bulkCopy = new SqlBulkCopy(m_dbAdapterContainer.Connection))
                    {
                        bulkCopy.BulkCopyTimeout      = 0;
                        bulkCopy.DestinationTableName = rangeLimitTable.TableName;
                        bulkCopy.WriteToServer(rangeLimitTable);
                    }
                }
            }
        }