Пример #1
0
        public static RpcMessage CreateInitializeMessage(string localAddress, string localHost)
        {
            // *** Create initialize message from passed in parameters ***

            RpcMessage returnMessage = new RpcMessage();

            //string msg = "[XWB]10304" + '\n' + "TCPConnect50" + LPack3(localAddress) + "f0" + LPack3("0") + "f0" + LPack3(localHost) + "f" + (char)4;
            string msgFormat = "[XWB]10304\nTCPConnect50{0}f0{1}f0{2}f" + (char)4;

            // *** Pack parameters ***
            string arg0 = returnMessage.LPack3(localAddress);
            string arg1 = returnMessage.LPack3("0");
            string arg2 = returnMessage.LPack3(localHost);

            // *** If status not error, then still good ***
            if (returnMessage.Status == RpcMessageStatus.Uknown)
            {
                returnMessage.Data   = string.Format(msgFormat, arg0, arg1, arg2);
                returnMessage.Status = RpcMessageStatus.Ready;
                returnMessage.InformationalMessage = "Message built successfully";
            }

            return(returnMessage);
        }
Пример #2
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);
        }