Beispiel #1
0
        /// <summary>
        /// Adds random values to write.
        /// </summary>
        private void AddWriteBadValues(
            TestVariable variable,
            WriteValueCollection nodesToWrite)
        {
            for (BuiltInType ii = BuiltInType.Null; ii < BuiltInType.DataValue; ii++)
            {
                if (variable.DataType != ii || variable.Variable.ValueRank >= 0)
                {
                    // add random scalar.
                    WriteValue nodeToWrite = new WriteValue();

                    nodeToWrite.NodeId      = variable.Variable.NodeId;
                    nodeToWrite.AttributeId = Attributes.Value;

                    DataValue value = new DataValue();

                    value.Value           = m_generator.GetRandom(ii);
                    value.StatusCode      = StatusCodes.Good;
                    value.ServerTimestamp = DateTime.MinValue;
                    value.SourceTimestamp = DateTime.MinValue;

                    variable.Values.Add(value);

                    nodeToWrite.Value  = value;
                    nodeToWrite.Handle = variable;

                    nodesToWrite.Add(nodeToWrite);
                }

                if (variable.DataType != ii || variable.Variable.ValueRank == ValueRanks.Scalar)
                {
                    // add random array.
                    WriteValue nodeToWrite = new WriteValue();

                    nodeToWrite.NodeId      = variable.Variable.NodeId;
                    nodeToWrite.AttributeId = Attributes.Value;

                    DataValue value = new DataValue();

                    value.Value           = m_generator.GetRandomArray(ii, true, 100, false);
                    value.StatusCode      = StatusCodes.Good;
                    value.ServerTimestamp = DateTime.MinValue;
                    value.SourceTimestamp = DateTime.MinValue;

                    variable.Values.Add(value);

                    nodeToWrite.Value  = value;
                    nodeToWrite.Handle = variable;

                    nodesToWrite.Add(nodeToWrite);
                }
            }
        }
        /// <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;
        }
Beispiel #3
0
        /// <summary>
        /// Creates new data.
        /// </summary>
        public void CreateData(ArchiveItem item)
        {
            // get the data set to use.
            DataSet dataset = item.DataSet;

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

            // generate one hour worth of data by default.
            DateTime 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)
            {
                int index = dataset.Tables[0].DefaultView.Count;
                DateTime endTime = (DateTime)dataset.Tables[0].DefaultView[index-1].Row[0];
                endTime = startTime.AddMilliseconds(item.SamplingInterval);
            }

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

            while (currentTime < DateTime.UtcNow)
            {
                DataValue dataValue = new DataValue();
                dataValue.SourceTimestamp = currentTime;
                dataValue.ServerTimestamp = currentTime.AddSeconds(generator.GetRandomByte());
                dataValue.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.
                DataRow 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;
        }