Пример #1
0
        public int TryInvokeRpcMethod(IRpcMethod method, object[] args, out object result)
        {
            DateTime time;

            base.EnsureRights(SymbolAccessRights.MethodInvoke);
            return(((IAccessorRpc)base.ValueAccessor).TryInvokeRpcMethod(this, method, args, out result, out time));
        }
Пример #2
0
        public int UnmarshalRpcMethod(IRpcMethod method, object[] parameterValues, byte[] data, out object returnValue)
        {
            object[]  values = null;
            IDataType type;
            int       offset = 0;

            this._resolver.TryResolveType(method.ReturnType, out type);
            offset += this.UnmarshalReturnValue(method, type, data, offset, out returnValue);
            return(offset + this.UnmarshalOutParameters(method, data, offset, out values));
        }
Пример #3
0
        public int TryInvokeRpcMethod(string methodName, object[] args, out object result)
        {
            IRpcMethod method = null;

            if (!((RpcStructType)base.DataType).RpcMethods.TryGetMethod(methodName, out method))
            {
                throw new ArgumentOutOfRangeException("methodName");
            }
            return(this.TryInvokeRpcMethod(method, args, out result));
        }
Пример #4
0
        public override int TryInvokeRpcMethod(IInstance instance, IRpcMethod method, object[] parameters, out object returnValue, out DateTime utcInvokeTime)
        {
            IAccessorRpc rpc = this._inner as IAccessorRpc;

            if (rpc != null)
            {
                return(rpc.TryInvokeRpcMethod(instance, method, parameters, out returnValue, out utcInvokeTime));
            }
            returnValue   = null;
            utcInvokeTime = DateTime.MinValue;
            return(0x701);
        }
Пример #5
0
        public virtual int GetInMarshallingSize(IRpcMethod method, object[] parameterValues)
        {
            int num = 0;
            RpcMethodParameterCollection parameters = null;
            IList <IDataType>            types      = null;

            this.GetInParameters(method, out parameters, out types);
            for (int i = 0; i < parameters.Count; i++)
            {
                num += this.OnGetParameterSize(i, parameters, parameterValues);
            }
            return(num);
        }
Пример #6
0
 public int UnmarshalOutParameters(IRpcMethod method, byte[] data, int offset, out object[] values)
 {
     if (method == null)
     {
         throw new ArgumentNullException("method");
     }
     if (data == null)
     {
         throw new ArgumentNullException("data");
     }
     if ((offset < 0) | (offset > data.Length))
     {
         throw new ArgumentOutOfRangeException("offset");
     }
     return(this.OnMarshalOut(method, data, offset, out values));
 }
Пример #7
0
        public virtual int GetOutMarshallingSize(IRpcMethod method, object[] outValues)
        {
            int num = 0;
            RpcMethodParameterCollection parameters = null;
            IList <IDataType>            types      = null;

            this.GetOutParameters(method, out parameters, out types);
            for (int i = 0; i < parameters.Count; i++)
            {
                num += this.OnGetParameterSize(i, parameters, outValues);
            }
            if (!string.IsNullOrEmpty(method.ReturnType))
            {
                num += this.OnGetMarshallingSize(method.ReturnType);
            }
            return(num);
        }
Пример #8
0
        protected virtual int OnMarshalOut(IRpcMethod method, byte[] data, int offset, out object[] values)
        {
            RpcMethodParameterCollection parameters = null;
            IList <IDataType>            types      = null;

            this.GetOutParameters(method, out parameters, out types);
            int num  = 0;
            int num2 = offset;

            values = new object[method.Parameters.Count];
            for (int i = 0; i < parameters.Count; i++)
            {
                num += this.OnUnmarshalParameter(i, parameters, types, data, num2, ref values);
                num2 = offset + num;
            }
            return(num);
        }
Пример #9
0
 protected int GetParameters(IRpcMethod method, MethodParamFlags mask, out RpcMethodParameterCollection parameters, out IList <IDataType> types)
 {
     types      = new List <IDataType>();
     parameters = new RpcMethodParameterCollection();
     for (int i = 0; i < method.Parameters.Count; i++)
     {
         if ((method.Parameters[i].ParameterFlags & mask) > ((MethodParamFlags)0))
         {
             IDataType type = null;
             if (!this._resolver.TryResolveType(method.Parameters[i].TypeName, out type))
             {
                 throw new ArgumentOutOfRangeException("parameters");
             }
             types.Add(type);
             parameters.Add(method.Parameters[i]);
         }
     }
     return(types.Count);
 }
Пример #10
0
        protected virtual int OnMarshalIn(IRpcMethod method, object[] parameterValues, byte[] buffer, int offset)
        {
            int num = 0;

            if (method.Parameters.Count > 0)
            {
                RpcMethodParameterCollection parameters = null;
                IList <IDataType>            types      = null;
                this.GetInParameters(method, out parameters, out types);
                if (parameters.Count != parameterValues.Length)
                {
                    throw new ArgumentOutOfRangeException("parameterValues");
                }
                for (int i = 0; i < parameters.Count; i++)
                {
                    num += this.OnMarshalParameter(i, parameters, types, parameterValues, buffer, offset + num);
                }
            }
            return(num);
        }
Пример #11
0
 public int MarshallParameters(IRpcMethod method, object[] parameterValues, byte[] buffer, int offset)
 {
     if (method == null)
     {
         throw new ArgumentNullException("method");
     }
     if (parameterValues == null)
     {
         throw new ArgumentNullException("parameterValues");
     }
     if (buffer == null)
     {
         throw new ArgumentNullException("data");
     }
     if ((offset < 0) || (offset > buffer.Length))
     {
         throw new ArgumentOutOfRangeException("offset");
     }
     return(this.OnMarshalIn(method, parameterValues, buffer, offset));
 }
Пример #12
0
        public override int TryInvokeRpcMethod(IInstance instance, IRpcMethod method, object[] parameters, out object returnValue, out DateTime invokeTime)
        {
            AdsErrorCode code;

            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }
            if (method == null)
            {
                throw new ArgumentNullException("method");
            }
            if (this.Connection == null)
            {
                throw new AdsException("Connection not established!");
            }
            string str = $"{instance.InstancePath}#{method.Name}";

            if (method.Parameters.Count != parameters.Length)
            {
                throw new ArgumentException($"Parameter set mismatching RpcMethod '{str}' prototype", "parameters");
            }
            invokeTime = DateTime.MinValue;
            IRpcCallableInstance instance2 = (IRpcCallableInstance)instance;
            IProcessImageAddress address   = (IProcessImageAddress)instance;

            using (new AdsConnectionRestore(this))
            {
                code = this.Connection.TryInvokeRpcMethod(instance.InstancePath, method.Name, parameters, out returnValue);
                if (code == AdsErrorCode.NoError)
                {
                    invokeTime = DateTime.UtcNow;
                }
            }
            return((int)code);
        }
Пример #13
0
 protected int GetOutParameters(IRpcMethod method, out RpcMethodParameterCollection parameters, out IList <IDataType> types) =>
 this.GetParameters(method, MethodParamFlags.ByReference | MethodParamFlags.Out, out parameters, out types);
Пример #14
0
 public abstract int UnmarshalReturnValue(IRpcMethod method, IDataType returnType, byte[] buffer, int offset, out object returnValue);
Пример #15
0
        public object InvokeRpcMethod(ITcAdsSymbol symbol, IRpcMethod rpcMethod, object[] parameterValues)
        {
            if (symbol == null)
            {
                throw new ArgumentNullException("symbol");
            }
            if (rpcMethod == null)
            {
                throw new ArgumentNullException("rpcMethod");
            }
            if (parameterValues == null)
            {
                throw new ArgumentNullException("parameters");
            }
            if (rpcMethod.Parameters.Count != parameterValues.Length)
            {
                throw new ArgumentOutOfRangeException("parameters", $"Parameter mismatch! The number of expected parameters is '{rpcMethod.Parameters.Count}");
            }
            object         returnValue  = null;
            string         variableName = $"{symbol.Name}#{rpcMethod.Name}";
            ITcAdsDataType type         = null;

            if (!rpcMethod.IsVoid)
            {
                type = (ITcAdsDataType)this._datatypeTable.ResolveDataType(rpcMethod.ReturnType);
            }
            List <IDataType> list = new List <IDataType>();

            foreach (RpcMethodParameter parameter in rpcMethod.Parameters)
            {
                ITcAdsDataType item = (ITcAdsDataType)this._datatypeTable.ResolveDataType(parameter.TypeName);
                if (item == null)
                {
                    throw new AdsDatatypeNotSupportedException();
                }
                list.Add(item);
            }
            int wrLength = 0;
            SymbolAdsMarshaller marshaller = new SymbolAdsMarshaller(this._datatypeTable);

            object[] objArray = new object[0];
            wrLength = marshaller.GetInMarshallingSize(rpcMethod, objArray);
            int outMarshallingSize = marshaller.GetOutMarshallingSize(rpcMethod, objArray);
            int variableHandle     = this._adsClient.CreateVariableHandle(variableName);

            try
            {
                byte[] buffer = new byte[wrLength];
                int    num4   = marshaller.MarshallParameters((RpcMethod)rpcMethod, parameterValues, buffer, 0);
                using (AdsStream stream = new AdsStream(buffer))
                {
                    using (AdsStream stream2 = new AdsStream(outMarshallingSize))
                    {
                        int num5 = 0;
                        num5 = this._adsClient.ReadWrite(variableHandle, stream2, 0, outMarshallingSize, stream, 0, wrLength);
                        if (outMarshallingSize > 0)
                        {
                            int num6 = marshaller.UnmarshalRpcMethod(rpcMethod, parameterValues, stream2.GetBuffer(), out returnValue);
                        }
                    }
                }
            }
            finally
            {
                this._adsClient.DeleteVariableHandle(variableHandle);
            }
            return(returnValue);
        }
 public abstract int TryInvokeRpcMethod(IInstance instance, IRpcMethod method, object[] parameters, out object returnValue, out DateTime utcInvokeTime);
Пример #17
0
 public override int UnmarshalReturnValue(IRpcMethod method, IDataType returnType, byte[] buffer, int offset, out object returnValue) =>
 this.unmarshal(buffer, offset, (ITcAdsDataType)returnType, out returnValue);