Example #1
0
        private void ListenLoop()
        {
            listener.Start();

            while (true)
            {
                connections.AddConnection(listener.AcceptTcpClient());
                manager.SendBroadCast();
            }
        }
    public void TwoNodeNeighbourTest()
    {
        Connections c = new Connections();

        c.AddConnection(0, 1);

        List <int> neighbours = c.GetNeighbours(0);

        Assert.AreEqual(1, neighbours.Count);
        Assert.IsTrue(neighbours.Contains(1));
        Assert.IsFalse(neighbours.Contains(0));

        c.AddConnection(0, 2);

        neighbours = c.GetNeighbours(0);
        Assert.AreEqual(2, neighbours.Count);
        Assert.IsTrue(neighbours.Contains(1));
        Assert.IsTrue(neighbours.Contains(2));
        Assert.IsFalse(neighbours.Contains(0));
    }
    public void TwoNodeOneWayConnectionTest()
    {
        Connections c = new Connections();

        c.AddConnection(0, 1);

        Assert.AreEqual(1, c.NumConnections);
        Assert.IsTrue(c.AreConnected(0, 1));
        Assert.IsFalse(c.AreConnected(0, 0));
        Assert.IsFalse(c.AreConnected(1, 0)); // one-way connection, 0->1, not 1->0
        Assert.IsFalse(c.AreConnected(1, 1));

        // Add another connection
        c.AddConnection(1, 2);

        Assert.AreEqual(2, c.NumConnections);
        Assert.IsTrue(c.AreConnected(1, 2));
        Assert.IsFalse(c.AreConnected(2, 1));
        Assert.IsFalse(c.AreConnected(2, 2));
        Assert.IsFalse(c.AreConnected(0, 2)); // not directly connected, this would only be found with a search
    }
Example #4
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            Validate();
            if (loadEdit)
            {
                Connections.RemoveConnection(cbListOfExistingConnections.SelectedValue.ToString());
                cbListOfExistingConnections.SelectedIndex = 0;
            }
            Connection myConn = new Connection(txtConName.Text, txtServerName.Text, txtIpAdd.Text, txtUserName.Text, txtPassword.Text, GlobalPassword.Password);

            Connections.AddConnection(myConn);
            txtClear_Click(sender, e);
            mainForm.loadConnectionsToListBox();
        }
Example #5
0
        private void Worker()
        {
            while (IsRunning)
            {
                try {
                    if (Socket.Poll(1000000, SelectMode.SelectRead))
                    {
                        Connections.AddConnection(new IRCConnection(this, Socket.Accept()));
                    }

                    Connections.GetReadyConnections(conns => {
                        foreach (IRCConnection conn in conns)
                        {
                            try {
                                int read       = conn.Receive(Buffer);
                                string[] lines = Encoding.UTF8.GetString(Buffer, 0, read).Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                                foreach (string line in lines)
                                {
                                    OnReceive(conn, line);
                                }
                            } catch (SocketException ex) {
                                Logger.Write($@"[IRC] Socket Error: {ex}");
                            }
                        }

                        // check pings

                        Connections.GetDeadConnections(conns => {
                            Queue <IRCConnection> dead = new Queue <IRCConnection>(conns);
                            while (dead.TryDequeue(out IRCConnection conn))
                            {
                                Connections.RemoveConnection(conn);
                                Context.Sessions.Destroy(conn);
                            }
                        });
                    });
                } catch (Exception ex) {
                    Logger.Write($@"[IRC] {ex}");
                }
            }
        }
Example #6
0
    public void GraphOneWayTest()
    {
        // Test pathfinding when we set up a graph with some one-way connections
        AStar astar = new AStar();

        Connections c = new Connections();

        // Set up a simple graph
        c.AddConnection(0, 1);
        c.AddConnection(1, 2);
        c.AddConnection(2, 3);
        c.AddConnection(4, 5);
        c.AddConnection(3, 6);
        c.AddConnection(2, 7);
        c.AddConnection(3, 7);

        List <int> path = new List <int>();

        // These paths should exist:
        Assert.IsTrue(astar.PathExists(c, 0, 1, path));
        Assert.AreEqual(2, path.Count);
        Assert.AreEqual(0, path[0]);
        Assert.AreEqual(1, path[1]);

        Assert.IsTrue(astar.PathExists(c, 0, 2, path));
        Assert.AreEqual(3, path.Count);
        Assert.AreEqual(0, path[0]);
        Assert.AreEqual(1, path[1]);
        Assert.AreEqual(2, path[2]);

        Assert.IsTrue(astar.PathExists(c, 0, 3, path));
        Assert.IsTrue(astar.PathExists(c, 4, 5, path));

        // These paths should not exist:
        Assert.IsFalse(astar.PathExists(c, 0, 5, path));
        Assert.IsFalse(astar.PathExists(c, 3, 5, path));

        // The connections in this Test are one-way, so paths do not exist going the other way
        Assert.IsFalse(astar.PathExists(c, 2, 0, path));
        Assert.IsFalse(astar.PathExists(c, 1, 0, path));
        Assert.IsFalse(astar.PathExists(c, 3, 0, path));
        Assert.IsFalse(astar.PathExists(c, 5, 4, path));
    }
Example #7
0
 private void OnOpen(SockChatConnection conn)
 {
     Logger.Debug($@"[{conn}] Connection opened");
     Connections.AddConnection(conn);
 }
    private static void ThrowsBecauseSecondIDNegative()
    {
        Connections c = new Connections();

        c.AddConnection(-1, 0);
    }