Ejemplo n.º 1
0
        internal static TraCICommand GetCommand(string id, byte commandType, byte messageType, List <string> values)
        {
            var bytes = new List <byte> {
                messageType
            };

            bytes.AddRange(TraCIDataConverter.GetTraCIBytesFromASCIIString(id));

            if (values != null && values.Count > 0)
            {
                bytes.Add(TraCIConstants.TYPE_STRINGLIST);
                bytes.AddRange(TraCIDataConverter.GetTraCIBytesFromInt32(values.Count));
                foreach (var parameter in values)
                {
                    bytes.AddRange(TraCIDataConverter.GetTraCIBytesFromASCIIString(parameter));
                }
            }
            var command = new TraCICommand
            {
                Identifier = commandType,
                Contents   = bytes.ToArray()
            };

            return(command);
        }
Ejemplo n.º 2
0
        internal static T ExecuteGetCommand <T>(TraCIClient client, string id, byte commandType, byte messageType)
        {
            var command  = GetCommand(id, commandType, messageType);
            var response = client.SendMessage(command);

            try
            {
                return((T)TraCIDataConverter.ExtractDataFromResponse(response, commandType, messageType));
            }
            catch
            {
                throw;
            }
        }
Ejemplo n.º 3
0
        internal static TraCICommand GetCommand(string id, byte commandType, byte messageType)
        {
            var bytes = new List <byte> {
                messageType
            };

            bytes.AddRange(TraCIDataConverter.GetTraCIBytesFromASCIIString(id));
            var command = new TraCICommand
            {
                Identifier = commandType,
                Contents   = bytes.ToArray()
            };

            return(command);
        }
Ejemplo n.º 4
0
        internal static Tres ExecuteSetCommand <Tres, Tvalue>(TraCIClient client, string id, byte commandType, byte messageType, Tvalue value)
        {
            TraCICommand command = null;

            switch (value)
            {
            case int i:
                command = GetCommand(id, commandType, messageType, i);
                break;

            case double d:
                command = GetCommand(id, commandType, messageType, d);
                break;

            case string s:
                command = GetCommand(id, commandType, messageType, s);
                break;

            case List <string> los:
                command = GetCommand(id, commandType, messageType, los);
                break;

            default:
            {
                throw new InvalidCastException($"Type {value.GetType().Name} is not implemented in method TraCICommandHelper.ExecuteSetCommand().");
            }
            }

            if (command != null)
            {
                var response = client.SendMessage(command);

                try
                {
                    return((Tres)TraCIDataConverter.ExtractDataFromResponse(response, commandType, messageType));
                }
                catch
                {
                    throw;
                }
            }
            else
            {
                return(default(Tres));
            }
        }
        internal static TraCIResponse <Tres> ExecuteSetCommand <Tres, Tvalue>(TraCIClient client, string id, byte commandType, byte messageType, Tvalue value)
        {
            TraCICommand command = null;

            switch (value)
            {
            case byte b:
                command = GetCommand(id, commandType, messageType, b);
                break;

            case int i:
                command = GetCommand(id, commandType, messageType, i);
                break;

            case double d:
                command = GetCommand(id, commandType, messageType, d);
                break;

            case string s:
                command = GetCommand(id, commandType, messageType, s);
                break;

            case List <string> los:
                command = GetCommand(id, commandType, messageType, los);
                break;

            case CompoundObject co:
                command = GetCommand(id, commandType, messageType, co);
                break;

            case Color c:
                command = GetCommand(id, commandType, messageType, c);
                break;

            case Position2D p2d:
                command = GetCommand(id, commandType, messageType, p2d);
                break;

            case Polygon p:
                command = GetCommand(id, commandType, messageType, p);
                break;

            case BoundaryBox bb:
                command = GetCommand(id, commandType, messageType, bb);
                break;

            default:
            {
                throw new InvalidCastException($"Type {value.GetType().Name} is not implemented in method TraCICommandHelper.ExecuteSetCommand().");
            }
            }

            if (command != null)
            {
                var response = client.SendMessage(command);

                try
                {
                    return(TraCIDataConverter.ExtractDataFromResponse <Tres>(response, commandType, messageType));
                }
                catch
                {
                    throw;
                }
            }
            else
            {
                return(default);