Esempio n. 1
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;
            }
        }
Esempio n. 2
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);