Esempio n. 1
0
        protected void Invoke(string name, params object[] parameters)
        {
            var method = new RemoteMethod
            {
                Name           = name,
                InputArguments = parameters.Select(iA => TypeMapping.ToVariant(iA)).ToList(),
                ReturnValue    = Variant.Null
            };

            Invoke(method);
        }
Esempio n. 2
0
        public T Invoke <T>(string name, params object[] parameters)
        {
            var method = new RemoteMethod
            {
                Name           = name,
                InputArguments = parameters.Select(iA => TypeMapping.ToVariant(iA)).ToList(),
                ReturnValue    = TypeMapping.MapType <T>()
            };

            var returnValue = Invoke(method);

            return((T)TypeMapping.ToObject(returnValue));
        }
Esempio n. 3
0
        private Variant Invoke(RemoteMethod method)
        {
            try
            {
                Variant result = method.Invoke(this);
                return(result);
            }
            catch (Exception e)
            {
                ExceptionHandler.Log(e, $"Cannot invoke {Name}.{method.Name}() without errors!");
            }

            return(method.HasReturnValue() ? method.ReturnValue : Variant.Null);
        }
Esempio n. 4
0
        public Variant CallMethod(RemoteMethod remoteMethod, ref NodeId methodNodeId)
        {
            var methodName = remoteMethod.Name;

            if (string.IsNullOrWhiteSpace(methodName))
            {
                throw new Exception("Method name is empty!");
            }

            if (_parentNode == null)
            {
                throw new Exception($"Parent node is null for method '{methodName}'!");
            }

            if (methodNodeId == NodeId.Null)
            {
                methodNodeId = BrowseNodeId(_parentNode, methodName, false);
            }

            List <StatusCode> inputArgumentErrors;
            List <Variant>    outputArguments;
            // call the method on the server.
            var result = _session.Call(
                _parentNode,
                methodNodeId,
                remoteMethod.InputArguments,
                out inputArgumentErrors,
                out outputArguments);

            if (remoteMethod.HasReturnValue() && outputArguments.Count > 0)
            {
                remoteMethod.ReturnValue = !result.IsGood() ? Variant.Null : outputArguments[0];
            }

            return(remoteMethod.ReturnValue);
        }