Beispiel #1
0
        /// <summary>
        /// 有命令请求时调用
        /// </summary>
        /// <param name="arg"></param>
        protected void OnClientCall(object arg)
        {
            CallArgument argument = (CallArgument)arg;
            string       result   = OnCall(argument);

            if (RpcEnvironment.NetState != ZmqNetStatus.Runing)
            {
                LogRecorder.Warning($"来自{argument.client}的请求操作已完成,但网络连接已关闭,无法返回。参数为{argument.callArg}");
                return;
            }
            argument.socket.TrySendFrame(timeOut, argument.client, true);
            argument.socket.TrySendFrameEmpty(timeOut, true);
            argument.socket.TrySendFrame(timeOut, result);
        }
Beispiel #2
0
 /// <summary>
 /// Calls function with given declaration on the given object. Object group of the result is inherited from the target object.
 /// </summary>
 /// <param name="objectId">Identifier of the object to call function on.</param>
 /// <param name="functionDeclaration">Declaration of the function to call.</param>
 /// <param name="arguments">(optional) Call arguments. All call arguments must belong to the same JavaScript world as the target object.</param>
 /// <param name="returnByValue">(optional) Whether the result is expected to be a JSON object which should be sent by value.</param>
 /// <returns>result (RemoteObject): Call result.
 /// wasThrown (optional boolean): True if the result was thrown during the evaluation.</returns>
 public static Command CallFunctionOn(string objectId, string functionDeclaration, CallArgument[] arguments = null, bool returnByValue = false)
 {
     var com = new Command("Runtime.callFunctionOn");
     com.addParam("objectId", objectId);
     com.addParam("functionDeclaration", functionDeclaration);
     if (arguments != null)
     {
         com.addParam("arguments", arguments);
     }
     if (returnByValue)
     {
         com.addParam("returnByValue", returnByValue);
     }
     return com;
 }
Beispiel #3
0
        /// <summary>
        /// 执行工作
        /// </summary>
        /// <param name="socket"></param>
        /// <returns>返回状态,其中-1会导致重连</returns>
        protected sealed override int DoWork(RequestSocket socket)
        {
            try
            {
                CallArgument argument = new CallArgument
                {
                    socket = socket
                };
                bool more;
                bool state = socket.TryReceiveFrameString(timeOut, out argument.client, out more);
                if (!state)
                {
                    return(0); //超时
                }
                if (!more)
                {
                    return(-1); //出错了
                }
                string empty;
                state = socket.TryReceiveFrameString(timeOut, out empty, out more);

                if (!state)
                {
                    return(0); //超时
                }
                if (!more)
                {
                    return(-1); //出错了
                }
                state = socket.TryReceiveFrameString(timeOut, out argument.callArg, out more);
                while (more)
                {
                    if (!state)
                    {
                        return(0); //超时
                    }
                    string str;
                    state = socket.TryReceiveFrameString(timeOut, out str, out more);
                }
                OnClientCall(argument);
            }
            catch (Exception ex)
            {
                OnException(socket, ex);
                return(-1);
            }
            return(1);
        }
Beispiel #4
0
        /// <summary>
        /// Extracts up the paramters specified in <see cref="Parameters"/> from <paramref name="arguments"/>
        /// and ddds the necessary properties to the call stack's target properties.
        /// </summary>
        /// <param name="arguments">The arguments being passed in to the this target</param>
        /// <param name="callStack">The call stack where the properties will be placed</param>
        /// <exception cref="ArgumentException">If one of the non-defaulted parameters is not satisfied by an argument.</exception>
        private void PrepareArguments(IList <CallArgument> arguments, TargetCallStack callStack)
        {
            if (this.Parameters == null || !this.Parameters.Parameters.Any())
            {
                return;
            }

            var accessor = new PropertyAccessor(this.Project, callStack);

            var matchedProperties = new HashSet <String>();

            foreach (var param in this.Parameters.Parameters)
            {
                if (matchedProperties.Contains(param.PropertyName))
                {
                    throw new BuildException(String.Format(@"Paramter ""{0}"" was declared more than once", param.PropertyName));
                }

                matchedProperties.Add(param.PropertyName);

                CallArgument arg = null;

                if (arguments != null)
                {
                    arg = arguments.FirstOrDefault(a => a.PropertyName.Equals(param.PropertyName));
                }

                if (arg == null && param.DefaultValue != null)
                {
                    accessor.Set(param.PropertyName, param.DefaultValue, PropertyScope.Target, false, true);
                }
                else if (arg != null)
                {
                    if (arguments.Count(a => a.PropertyName.Equals(arg.PropertyName)) > 1)
                    {
                        throw new ArgumentException(String.Format(@"Argument ""{0}"" was specified more than once.", param.PropertyName));
                    }

                    accessor.Set(param.PropertyName, arg.PropertyValue, PropertyScope.Target, false, true);
                }
                else
                {
                    throw new ArgumentException(String.Format(@"Target ""{0}"" requires parameter ""{1}"" but it was not provided and has no default.", this.Name, param.PropertyName));
                }
            }
        }
Beispiel #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="argument"></param>
 /// <returns></returns>
 protected virtual string OnCall(CallArgument argument)
 {
     return($"{{\"Result\":false,\"Id\":{Thread.CurrentThread.ManagedThreadId}}}");
 }
Beispiel #6
0
 public void AddArgument(CallArgument arg)
 {
     this.arguments.Add(arg);
 }