Ejemplo n.º 1
0
        public static RpcMessage CreateRpcMessage(string api, string rpcver, List <RpcParameter> parameterList)
        {
            // *** Creates an RPC Message object ***

            RpcMessage returnMessage = new RpcMessage();

            // *** Attampt to construct an rpc message string from parameters ***

            StringBuilder messageBuilder    = new StringBuilder();
            StringBuilder parametersBuilder = new StringBuilder();

            messageBuilder.Append(xwbPrefix);
            messageBuilder.Append("11302");

            string temp = returnMessage.SPack(rpcver);

            messageBuilder.Append(temp);

            temp = returnMessage.SPack(api);
            messageBuilder.Append(temp);

            parametersBuilder.Append("5");

            if (parameterList != null)
            {
                foreach (RpcParameter param in parameterList)
                {
                    switch (param.ParameterType)
                    {
                    case RpcParameterType.Literal:
                        parametersBuilder.Append("0" + returnMessage.LPack3(param.Value) + "f");
                        break;

                    case RpcParameterType.Reference:
                        parametersBuilder.Append("1" + returnMessage.LPack3(param.Value) + "f");
                        break;

                    case RpcParameterType.Empty:
                        parametersBuilder.Append("4f");
                        break;

                    case RpcParameterType.List:
                        parametersBuilder.Append("2" + returnMessage.AddMults(param.Mult));
                        break;

                    case RpcParameterType.Global:
                        parametersBuilder.Append("3" + returnMessage.AddMults(param.Mult));
                        break;

                    case RpcParameterType.Stream:
                        parametersBuilder.Append("5" + returnMessage.LPack3(param.Value) + 'f');
                        break;
                    }
                }
            }

            if (parametersBuilder.ToString() == "5")
            {
                parametersBuilder.Append("4f");
            }

            messageBuilder.Append(parametersBuilder.ToString());

            messageBuilder.Append("\x4");

            if (returnMessage.Status == RpcMessageStatus.Uknown)
            {
                returnMessage.Data   = messageBuilder.ToString();
                returnMessage.Status = RpcMessageStatus.Ready;
                returnMessage.InformationalMessage = "Message built successfully";
            }

            return(returnMessage);
        }