示例#1
0
        public static void ClientDisconnected(string userId, int clientId)
        {
            if (!UsersCollection.ContainsKey(userId) || !UsersCollection[userId].Clients.ContainsKey(clientId))
            {
                return;
            }

            User.Client client = UsersCollection[userId].Clients[clientId];
            lock (UsersCollection)
            {
                UsersCollection[userId].Clients.Remove(clientId);
                UsersCollection[userId].ResByteReceived += client.ByteReceived;
                UsersCollection[userId].ResByteSent     += client.ByteSent;
            }
        }
示例#2
0
        public static void ChangeUser(string lastUserId, string newUserId, int clientId)
        {
            if (!UsersCollection.ContainsKey(lastUserId) || !UsersCollection[lastUserId].Clients.ContainsKey(clientId))
            {
                return;
            }

            lock (UsersCollection)
            {
                if (!UsersCollection.ContainsKey(newUserId))
                {
                    UsersCollection.Add(newUserId, new User(usageLogEnable, usageLogAddress, newUserId));
                }

                User.Client client = UsersCollection[lastUserId].Clients[clientId];
                UsersCollection[lastUserId].Clients.Remove(clientId);
                UsersCollection[newUserId].Clients.Add(clientId, client);
            }
        }
示例#3
0
        public static void ReDraw(PeaRoxyController ctrl, bool show = true)
        {
            ClearConsole();
            try
            {
                long byteReceived = 0;
                long byteSent     = 0;
                long downSpeed    = 0;
                long upSpeed      = 0;
                lock (UsersCollection)
                {
                    for (int i = 0; i < UsersCollection.Values.Count; i++)
                    {
                        User user = UsersCollection.Values.ElementAt(i);
                        user.Update(show);
                        if (show && user.Clients.Count > 0)
                        {
                            Console.WriteLine(
                                "     " + PrintWithSpaceAfter(user.Id) + "Active Connections: "
                                + PrintWithSpaceAfter(user.Clients.Count.ToString(CultureInfo.InvariantCulture), 4)
                                + PrintWithSpaceAfter(Common.FormatFileSizeAsString(user.ByteReceived))
                                + PrintWithSpaceAfter(Common.FormatFileSizeAsString(user.ByteSent))
                                + PrintWithSpaceAfter(Common.FormatFileSizeAsString(user.DownSpeed))
                                + PrintWithSpaceAfter(Common.FormatFileSizeAsString(user.UpSpeed)));
                            Console.WriteLine(
                                PrintWithSpaceAfter("IP", 19) + PrintWithSpaceAfter("REQ", 20)
                                + PrintWithSpaceAfter("DOWN") + PrintWithSpaceAfter("UP")
                                + PrintWithSpaceAfter("DOWN PS") + PrintWithSpaceAfter("UP PS"));
                            try
                            {
                                for (int j = 0; j < user.Clients.Values.Count; j++)
                                {
                                    User.Client client        = user.Clients.Values.ElementAt(j);
                                    string      remoteAddress = client.RemoteAddress;
                                    if (remoteAddress.Length > 18)
                                    {
                                        remoteAddress = remoteAddress.Substring(0, 18);
                                    }

                                    string requestAddress = client.RequestAddress;
                                    if (requestAddress.Length > 19)
                                    {
                                        requestAddress = requestAddress.Substring(0, 19);
                                    }

                                    Console.WriteLine(
                                        PrintWithSpaceAfter(remoteAddress, 19) + PrintWithSpaceAfter(requestAddress, 20)
                                        + PrintWithSpaceAfter(Common.FormatFileSizeAsString(client.ByteReceived))
                                        + PrintWithSpaceAfter(Common.FormatFileSizeAsString(client.ByteSent))
                                        + PrintWithSpaceAfter(Common.FormatFileSizeAsString(client.DownSpeed))
                                        + PrintWithSpaceAfter(Common.FormatFileSizeAsString(client.UpSpeed)));
                                }
                            }
                            catch (Exception)
                            {
                            }

                            WriteHr();
                            WriteHr(' ');
                        }

                        byteReceived += user.ByteReceived;
                        byteSent     += user.ByteSent;
                        downSpeed    += user.DownSpeed;
                        upSpeed      += user.UpSpeed;
                    }
                }

                Console.WriteLine(
                    "Downloaded: " + PrintWithSpaceAfter(Common.FormatFileSizeAsString(byteReceived)) + "Uploaded: "
                    + PrintWithSpaceAfter(Common.FormatFileSizeAsString(byteSent)) + "Down PS: "
                    + PrintWithSpaceAfter(Common.FormatFileSizeAsString(downSpeed)) + "Up PS: "
                    + PrintWithSpaceAfter(Common.FormatFileSizeAsString(upSpeed)));
                Console.WriteLine(
                    "Accepting Cycle: "
                    + PrintWithSpaceAfter(ctrl.AcceptingCycle.ToString(CultureInfo.InvariantCulture))
                    + "Routing Cycle: " + PrintWithSpaceAfter(ctrl.RoutingCycle.ToString(CultureInfo.InvariantCulture)));
            }
            catch (Exception)
            {
            }
        }