Exemplo n.º 1
0
 /// <summary>
 /// Callback for <see cref="TorXakisConnection.StateChanged"/>.
 /// </summary>
 private void Connection_StateChanged(TorXakisConnection connection)
 {
     // Once all connections have been established, we are ready to begin the test run.
     if (connections.All(x => x.Value.State == TorXakisConnection.States.Connected))
     {
         // TODO!
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Adds the given <see cref="TorXakisConnection"/> to <see cref="connections"/>.
        /// </summary>
        private void AddConnection(TorXakisConnection connection)
        {
            if (connections.TryGetValue(connection.Port, out TorXakisConnection existing))
            {
                throw new ArgumentException("Port is already taken by: " + existing);
            }

            connections.Add(connection.Port, connection);
            connection.StateChanged  += Connection_StateChanged;
            connection.InputReceived += Connection_InputReceived;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Adds the given <see cref="TorXakisConnection"/> to <see cref="connections"/>.
        /// </summary>
        private void RemoveConnection(TorXakisConnection connection)
        {
            if (!connections.ContainsKey(connection.Port))
            {
                throw new ArgumentException("Port is not registered: " + connection);
            }

            connections.Remove(connection.Port);
            connection.StateChanged  -= Connection_StateChanged;
            connection.InputReceived -= Connection_InputReceived;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Parses the <see cref="Model"/> file for all required information (such as the defined TCP channels).
        /// </summary>
        private void ParseModel()
        {
            Dictionary <int, List <string> > parsed = Model.ParseConnections();

            // Create the parsed connections.
            foreach (KeyValuePair <int, List <string> > kvp in parsed)
            {
                TorXakisConnection connection = new TorXakisConnection(kvp.Key, kvp.Value[0], kvp.Value[1]);
                AddConnection(connection);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Sends the given output, in a blocking fashion.
        /// </summary>
        public bool SendOutput(TorXakisAction action)
        {
            lock (locker)
            {
                // Sanity checks.
                if (action.Type != ActionType.Output)
                {
                    throw new ArgumentException("Not output: " + action);
                }

                TorXakisConnection connection = connections.Values.FirstOrDefault(x => x.OutputChannel == action.Channel);
                if (connection == null)
                {
                    throw new Exception("Connection not found for: " + action);
                }
                Log.Info(this, nameof(SendOutput) + ": " + action);
                return(connection.SendOutput(action));
            }
        }