Exemplo n.º 1
0
#pragma warning disable RECS0154 // Parameter is never used
        /// <summary>
        /// Loads the item configuaration.
        /// </summary>
        public bool LoadConfiguration(ISystemContext context, ArchiveItem item)
#pragma warning restore RECS0154 // Parameter is never used
        {
            using (var reader = item.OpenArchive()) {
                while (!reader.EndOfStream)
                {
                    var line = reader.ReadLine();

                    // check for end or error.
                    if (line == null)
                    {
                        break;
                    }

                    // ignore blank lines.
                    line = line.Trim();

                    if (string.IsNullOrEmpty(line))
                    {
                        continue;
                    }

                    // ignore commented out lines.
                    if (line.StartsWith("//", StringComparison.CurrentCulture))
                    {
                        continue;
                    }

                    var dataType  = BuiltInType.String;
                    var valueRank = ValueRanks.Scalar;

                    // get data type.
                    if (!ExtractField(1, ref line, out dataType))
                    {
                        return(false);
                    }

                    // get value rank.
                    if (!ExtractField(1, ref line, out valueRank))
                    {
                        return(false);
                    }

                    // get sampling interval.
                    if (!ExtractField(1, ref line, out int samplingInterval))
                    {
                        return(false);
                    }

                    // get simulation type.
                    if (!ExtractField(1, ref line, out int simulationType))
                    {
                        return(false);
                    }

                    // get simulation amplitude.
                    if (!ExtractField(1, ref line, out int amplitude))
                    {
                        return(false);
                    }

                    // get simulation period.
                    if (!ExtractField(1, ref line, out int period))
                    {
                        return(false);
                    }

                    // get flag indicating whether new data is generated.
                    if (!ExtractField(1, ref line, out int archiving))
                    {
                        return(false);
                    }

                    // get flag indicating whether stepped interpolation is used.
                    if (!ExtractField(1, ref line, out int stepped))
                    {
                        return(false);
                    }

                    // get flag indicating whether sloped interpolation should be used.
                    if (!ExtractField(1, ref line, out int useSlopedExtrapolation))
                    {
                        return(false);
                    }

                    // get flag indicating whether sloped interpolation should be used.
                    if (!ExtractField(1, ref line, out int treatUncertainAsBad))
                    {
                        return(false);
                    }

                    // get the maximum permitted of bad data in an interval.
                    if (!ExtractField(1, ref line, out int percentDataBad))
                    {
                        return(false);
                    }

                    // get the minimum amount of good data in an interval.
                    if (!ExtractField(1, ref line, out int percentDataGood))
                    {
                        return(false);
                    }

                    // update the item.
                    item.DataType               = dataType;
                    item.ValueRank              = valueRank;
                    item.SimulationType         = simulationType;
                    item.Amplitude              = amplitude;
                    item.Period                 = period;
                    item.SamplingInterval       = samplingInterval;
                    item.Archiving              = archiving != 0;
                    item.Stepped                = stepped != 0;
                    item.AggregateConfiguration = new AggregateConfiguration {
                        UseServerCapabilitiesDefaults = false,
                        UseSlopedExtrapolation        = useSlopedExtrapolation != 0,
                        TreatUncertainAsBad           = treatUncertainAsBad != 0,
                        PercentDataBad  = (byte)percentDataBad,
                        PercentDataGood = (byte)percentDataGood
                    };
                    break;
                }
            }

            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates new data.
        /// </summary>
        public void CreateData(ArchiveItem item)
        {
            // get the data set to use.
            var dataset = item.DataSet;

            if (dataset == null)
            {
                dataset = CreateDataSet();
            }

            // generate one hour worth of data by default.
            var startTime = DateTime.UtcNow.AddHours(-1);

            startTime = new DateTime(startTime.Year, startTime.Month, startTime.Day, startTime.Hour, 0, 0, DateTimeKind.Utc);

            // check for existing data.
            if (dataset.Tables[0].Rows.Count > 0)
            {
                var index   = dataset.Tables[0].DefaultView.Count;
                var endTime = (DateTime)dataset.Tables[0].DefaultView[index - 1].Row[0];
                endTime = startTime.AddMilliseconds(item.SamplingInterval);
            }

            var currentTime = startTime;
            var generator   = new Opc.Ua.Test.DataGenerator(null);

            while (currentTime < DateTime.UtcNow)
            {
                var dataValue = new DataValue {
                    SourceTimestamp = currentTime,
                    ServerTimestamp = currentTime.AddSeconds(generator.GetRandomByte()),
                    StatusCode      = StatusCodes.Good
                };

                // generate random value.
                if (item.ValueRank < 0)
                {
                    dataValue.Value = generator.GetRandom(item.DataType);
                }
                else
                {
                    dataValue.Value = generator.GetRandomArray(item.DataType, false, 10, false);
                }

                // add record to table.
                var row = dataset.Tables[0].NewRow();

                row[0] = dataValue.SourceTimestamp;
                row[1] = dataValue.ServerTimestamp;
                row[2] = dataValue;
                row[3] = dataValue.WrappedValue.TypeInfo.BuiltInType;
                row[4] = dataValue.WrappedValue.TypeInfo.ValueRank;

                dataset.Tables[0].Rows.Add(row);

                // increment timestamp.
                currentTime = currentTime.AddMilliseconds(item.SamplingInterval);
            }

            dataset.AcceptChanges();
            item.DataSet = dataset;
        }