Ejemplo n.º 1
0
        /// <summary>
        /// Decode the arguments for a procedure from a serialized request
        /// </summary>
        object[] DecodeArguments(ProcedureSignature procedure, IList <Argument> arguments)
        {
            // Rearrange argument values
            var argumentValues = new ByteString [procedure.Parameters.Count];

            foreach (var argument in arguments)
            {
                argumentValues [argument.Position] = argument.Value;
            }

            var decodedArgumentValues = new object[procedure.Parameters.Count];

            for (int i = 0; i < procedure.Parameters.Count; i++)
            {
                var type  = procedure.Parameters [i].Type;
                var value = argumentValues [i];
                if (value == null)
                {
                    // Handle default arguments
                    if (!procedure.Parameters [i].HasDefaultArgument)
                    {
                        throw new RPCException(procedure, "Argument not specified for parameter " + procedure.Parameters [i].Name + " in " + procedure.FullyQualifiedName + ". ");
                    }
                    decodedArgumentValues [i] = Type.Missing;
                }
                else
                {
                    // Decode argument
                    try {
                        decodedArgumentValues [i] = Decode(procedure, i, type, value);
                    } catch (Exception e) {
                        throw new RPCException(
                                  procedure,
                                  "Failed to decode argument for parameter " + procedure.Parameters [i].Name + " in " + procedure.FullyQualifiedName + ". " +
                                  "Expected an argument of type " + TypeUtils.GetTypeName(type) + ". " +
                                  e.GetType().Name + ": " + e.Message);
                    }
                }
            }
            return(decodedArgumentValues);
        }
Ejemplo n.º 2
0
        public static Messages.Services GetServices()
        {
            var services = new Messages.Services();

            foreach (var serviceSignature in Services.Instance.Signatures.Values)
            {
                var service = new Messages.Service(serviceSignature.Name);
                foreach (var procedureSignature in serviceSignature.Procedures.Values)
                {
                    var procedure = new Procedure(procedureSignature.Name);
                    if (procedureSignature.HasReturnType)
                    {
                        procedure.ReturnType = TypeUtils.GetTypeName(procedureSignature.ReturnType);
                    }
                    foreach (var parameterSignature in procedureSignature.Parameters)
                    {
                        var parameter = new Parameter(parameterSignature.Name, TypeUtils.GetTypeName(parameterSignature.Type));
                        if (parameterSignature.HasDefaultValue)
                        {
                            parameter.DefaultValue = parameterSignature.DefaultValue;
                        }
                        procedure.Parameters.Add(parameter);
                    }
                    foreach (var attribute in procedureSignature.Attributes)
                    {
                        procedure.Attributes.Add(attribute);
                    }
                    if (procedureSignature.Documentation.Length > 0)
                    {
                        procedure.Documentation = procedureSignature.Documentation;
                    }
                    service.Procedures.Add(procedure);
                }
                foreach (var clsSignature in serviceSignature.Classes.Values)
                {
                    var cls = new Class(clsSignature.Name);
                    if (clsSignature.Documentation.Length > 0)
                    {
                        cls.Documentation = clsSignature.Documentation;
                    }
                    service.Classes.Add(cls);
                }
                foreach (var enmSignature in serviceSignature.Enumerations.Values)
                {
                    var enm = new Enumeration(enmSignature.Name);
                    if (enmSignature.Documentation.Length > 0)
                    {
                        enm.Documentation = enmSignature.Documentation;
                    }
                    foreach (var enmValueSignature in enmSignature.Values)
                    {
                        var enmValue = new EnumerationValue(enmValueSignature.Name, enmValueSignature.Value);
                        if (enmValueSignature.Documentation.Length > 0)
                        {
                            enmValue.Documentation = enmValueSignature.Documentation;
                        }
                        enm.Values.Add(enmValue);
                    }
                    service.Enumerations.Add(enm);
                }
                if (serviceSignature.Documentation.Length > 0)
                {
                    service.Documentation = serviceSignature.Documentation;
                }
                services.ServicesList.Add(service);
            }
            return(services);
        }
Ejemplo n.º 3
0
        public static Schema.KRPC.Services GetServices()
        {
            var services = new Schema.KRPC.Services();

            foreach (var serviceSignature in Services.Instance.Signatures.Values)
            {
                var service = new Schema.KRPC.Service();
                service.Name = serviceSignature.Name;
                foreach (var procedureSignature in serviceSignature.Procedures.Values)
                {
                    var procedure = new Procedure();
                    procedure.Name = procedureSignature.Name;
                    if (procedureSignature.HasReturnType)
                    {
                        procedure.HasReturnType = true;
                        procedure.ReturnType    = TypeUtils.GetTypeName(procedureSignature.ReturnType);
                    }
                    foreach (var parameterSignature in procedureSignature.Parameters)
                    {
                        var parameter = new Parameter();
                        parameter.Name = parameterSignature.Name;
                        parameter.Type = TypeUtils.GetTypeName(parameterSignature.Type);
                        if (parameterSignature.HasDefaultArgument)
                        {
                            parameter.HasDefaultArgument = true;
                            parameter.DefaultArgument    = parameterSignature.DefaultArgument;
                        }
                        procedure.Parameters.Add(parameter);
                    }
                    foreach (var attribute in procedureSignature.Attributes)
                    {
                        procedure.Attributes.Add(attribute);
                    }
                    if (procedureSignature.Documentation != "")
                    {
                        procedure.Documentation = procedureSignature.Documentation;
                    }
                    service.Procedures.Add(procedure);
                }
                foreach (var clsSignature in serviceSignature.Classes.Values)
                {
                    var cls = new Class();
                    cls.Name = clsSignature.Name;
                    if (clsSignature.Documentation != "")
                    {
                        cls.Documentation = clsSignature.Documentation;
                    }
                    service.Classes.Add(cls);
                }
                foreach (var enmSignature in serviceSignature.Enumerations.Values)
                {
                    var enm = new Enumeration();
                    enm.Name = enmSignature.Name;
                    if (enmSignature.Documentation != "")
                    {
                        enm.Documentation = enmSignature.Documentation;
                    }
                    foreach (var enmValueSignature in enmSignature.Values)
                    {
                        var enmValue = new EnumerationValue();
                        enmValue.Name  = enmValueSignature.Name;
                        enmValue.Value = enmValueSignature.Value;
                        if (enmValueSignature.Documentation != "")
                        {
                            enmValue.Documentation = enmValueSignature.Documentation;
                        }
                        enm.Values.Add(enmValue);
                    }
                    service.Enumerations.Add(enm);
                }
                if (serviceSignature.Documentation != "")
                {
                    service.Documentation = serviceSignature.Documentation;
                }
                services.Services_.Add(service);
            }
            return(services);
        }