Пример #1
0
        /// <summary>
        /// Adds random values to write.
        /// </summary>
        private void AddWriteValues(
            TestVariable variable,
            WriteValueCollection nodesToWrite)
        {
            WriteValue nodeToWrite = new WriteValue();

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

            DataValue value = new DataValue();

            value.Value = m_generator.GetRandom(
                variable.Variable.DataType,
                variable.Variable.ValueRank,
                variable.Variable.ArrayDimensions,
                Session.TypeTree);

            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);
        }
Пример #2
0
        /// <summary>
        /// Handles a method call.
        /// </summary>
        private ServiceResult DoGenerateRandomValues(
            ISystemContext context,
            MethodState method,
            IList <object> inputArguments,
            IList <object> outputArguments)
        {
            ComDaClientManager system = (ComDaClientManager)this.SystemContext.SystemHandle;
            ComDaClient        client = system.SelectClient((ServerSystemContext)context, false);

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

            IDaElementBrowser browser = client.CreateBrowser((string)method.Handle);

            // create write requests.
            WriteRequestCollection requests = new WriteRequestCollection();

            try
            {
                for (DaElement element = browser.Next(); element != null; element = browser.Next())
                {
                    if (element.ElementType == DaElementType.Branch)
                    {
                        continue;
                    }

                    // generate a random value of the correct data tyoe.
                    bool   isArray    = false;
                    NodeId dataTypeId = ComUtils.GetDataTypeId(element.DataType, out isArray);

                    object value = generator.GetRandom(
                        dataTypeId,
                        (isArray)?ValueRanks.OneDimension:ValueRanks.Scalar,
                        null,
                        context.TypeTable);

                    // create a request.
                    requests.Add(new Opc.Ua.Com.Client.WriteRequest(element.ItemId, new DataValue(new Variant(value)), 0));
                }
            }
            finally
            {
                browser.Dispose();
            }

            // write values.
            client.Write(requests);

            return(ServiceResult.Good);
        }
        private object GetNewValue(BaseVariableState variable)
        {
            if (generator_ == null)
            {
                generator_ = new Opc.Ua.Test.DataGenerator(null)
                {
                    BoundaryValueFrequency = 0
                };
            }

            object value      = null;
            var    retryCount = 0;

            while (value == null && retryCount < 10)
            {
                value = generator_.GetRandom(variable.DataType, variable.ValueRank, new uint[] { 10 }, opcServer_.NodeManager.ServerData.TypeTree);
                retryCount++;
            }
            return(value);
        }
        //geting new value for the variable
        private object GetNewValue(BaseVariableState variable)
        {
            if (m_generator == null)
            {
                m_generator = new Opc.Ua.Test.DataGenerator(null)
                {
                    BoundaryValueFrequency = 0
                };
            }
            object value      = null;
            int    retryCount = 0;

            while (value == null && retryCount < 10)
            {
                value = m_generator.GetRandom(variable.DataType, variable.ValueRank, new uint[] { 10 }, Server.TypeTree);
                retryCount++;
            }
            System.Console.WriteLine("into generationg new value   " + value);
            return(value);
        }
Пример #5
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;
        }
Пример #6
0
        /// <summary>
        /// Adds random parameters
        /// </summary>
        private void AddMethodCall(
            TestMethod method,
            CallMethodRequestCollection methodsToCall,
            bool testErrors)
        {
            VariantCollection inputArguments = new VariantCollection();

            for (int ii = 0; ii < method.InputArguments.Count; ii++)
            {
                Argument argument = method.InputArguments[ii];

                object value = m_generator.GetRandom(
                    argument.DataType,
                    argument.ValueRank,
                    argument.ArrayDimensions,
                    Session.TypeTree);

                inputArguments.Add(new Variant(value));
            }

            CallMethodRequest request = null;

            // add valid method.
            if (!testErrors)
            {
                request = new CallMethodRequest();

                request.ObjectId       = method.Parent.NodeId;
                request.MethodId       = method.Method.NodeId;
                request.Handle         = method;
                request.InputArguments = new VariantCollection(inputArguments);

                methodsToCall.Add(request);

                return;
            }

            // add invalid object.
            request = new CallMethodRequest();

            request.ObjectId       = Objects.RootFolder;
            request.MethodId       = method.Method.NodeId;
            request.Handle         = method;
            request.InputArguments = new VariantCollection(inputArguments);

            methodsToCall.Add(request);

            if (inputArguments.Count > 0)
            {
                // add too few parameters.
                request = new CallMethodRequest();

                request.ObjectId       = method.Parent.NodeId;
                request.MethodId       = method.Method.NodeId;
                request.Handle         = method;
                request.InputArguments = new VariantCollection(inputArguments);
                request.InputArguments.RemoveAt(request.InputArguments.Count - 1);

                methodsToCall.Add(request);

                // add invalid parameter.
                request = new CallMethodRequest();

                request.ObjectId       = method.Parent.NodeId;
                request.MethodId       = method.Method.NodeId;
                request.Handle         = method;
                request.InputArguments = new VariantCollection(inputArguments);

                Argument argument = method.InputArguments[inputArguments.Count / 2];

                if (TypeInfo.GetBuiltInType(argument.DataType, Session.TypeTree) != BuiltInType.Variant)
                {
                    TypeInfo typeInfo = null;

                    do
                    {
                        Variant arg = (Variant)m_generator.GetRandom(BuiltInType.Variant);

                        typeInfo = TypeInfo.IsInstanceOfDataType(
                            arg.Value,
                            argument.DataType,
                            argument.ValueRank,
                            Session.NamespaceUris,
                            Session.TypeTree);

                        if (typeInfo == null)
                        {
                            request.InputArguments[inputArguments.Count / 2] = arg;
                            methodsToCall.Add(request);
                            break;
                        }
                    }while (typeInfo != null);
                }
            }

            // add extra parameters.
            request = new CallMethodRequest();

            request.ObjectId       = method.Parent.NodeId;
            request.MethodId       = method.Method.NodeId;
            request.Handle         = method;
            request.InputArguments = new VariantCollection(inputArguments);
            request.InputArguments.Add(new Variant(m_generator.GetRandom(BuiltInType.Variant)));

            methodsToCall.Add(request);
        }
Пример #7
0
        /// <summary>
        /// Handles a method call.
        /// </summary>
        private ServiceResult DoGenerateRandomValues(
            ISystemContext context,
            MethodState method,
            IList<object> inputArguments,
            IList<object> outputArguments)
        {
            ComDaClientManager system = (ComDaClientManager)this.SystemContext.SystemHandle;
            ComDaClient client = system.SelectClient((ServerSystemContext)context, false);

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

            IDaElementBrowser browser = client.CreateBrowser((string)method.Handle);

            // create write requests.
            WriteRequestCollection requests = new WriteRequestCollection();

            try
            {
                for (DaElement element = browser.Next(); element != null; element = browser.Next())
                {
                    if (element.ElementType == DaElementType.Branch)
                    {
                        continue;
                    }

                    // generate a random value of the correct data tyoe.
                    bool isArray = false;
                    NodeId dataTypeId = ComUtils.GetDataTypeId(element.DataType, out isArray);
                    
                    object value = generator.GetRandom(
                        dataTypeId, 
                        (isArray)?ValueRanks.OneDimension:ValueRanks.Scalar, 
                        null, 
                        context.TypeTable);

                    // create a request.
                    requests.Add(new Opc.Ua.Com.Client.WriteRequest(element.ItemId, new DataValue(new Variant(value)), 0));
                }
            }
            finally
            {
                browser.Dispose();
            }

            // write values.
            client.Write(requests);

            return ServiceResult.Good;
        }
Пример #8
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;
        }