Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ClientManager"/> class.
        /// </summary>
        public ClientManager(string ip, int port)
        {
            // Check if the framework is compatible:
            if (!OSRequirements.Framework())
            {
                throw new PlatformNotSupportedException("The required version of .NET Framework is not installed on this machine.");
            }

            // Set the connection status instance:
            ConnectionStatus = new ConnectionStatus(this);

            // Set the chatroom manager instance:
            ChatroomManager = new ChatroomManager(this);

            // Set the packet manager instance:
            PacketManager = new PacketManager();

            // Set the ip address and port for the client manager:
            IPAddress = ip;
            Port      = port;

            // Subscribe to the 'connection succeed' event
            ConnectionSucceed += ClientManager_ConnectionSucceed;

            // Subscribe to the 'connection failed' event
            ConnectionFailed += ClientManager_ConnectionFailed;
        }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ServerManager"/> class.
 /// </summary>
 public ServerManager(int port)
 {
     PacketManager        = new PacketManager();
     ConnectionController = new ConnectionController(port, this);
     ChatroomManager      = new ChatroomManager(this);
     PrivateRoomManager   = new PrivateRoomManager(this);
     DatabaseManager      = new DatabaseManager(this, false);
 }
Пример #3
0
 /// <summary>
 /// Client constructor
 /// </summary>
 public Client()
 {
     user            = new User();
     chatroomManager = new ChatroomManager();
     UserManager     = new UserManager();
     Quit            = false;
     logged          = false;
 }
Пример #4
0
 /// <summary>
 /// Instanciate objects
 /// Load Users and Chatrooms already stored in a static file
 /// </summary>
 public Server()
 {
     userManager = new UserManager();
     userManager.load("users.db");
     sessionManager = new SessionManager();
     chatroomManager = new ChatroomManager();
     chatroomManager.load("chatrooms.db");
     readLock = new Object();
 }
Пример #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.User == null || !this.User.Identity.IsAuthenticated)
            {
                Response.Redirect("~/Error/AuthError.aspx?source=Chatroom");
            }
            else if (this.User.IsInRole("Administrator"))
            {
                currentUser = Administrator.Get();
            }
            else
            {
                currentUser = DatabaseUtilities.GetUser(this.User.Identity.Name);
            }

            cr = ChatroomManager.GetChatroom(currentUser.GroupNumber);
            // register this page with the Chatroom
            cr.RegisterReceiver(this);
            // put all the messages in the chatroom on the page
            PopulateChatMessages();
        }
Пример #6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // send the user to the login page if they are not logged in
            if ((System.Web.HttpContext.Current.User == null) ||
                !System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
            {
                Response.Redirect("~/Account/Login");
            }

            // populate a user object with the user's details
            if (this.User.IsInRole("Administator"))
            {
                currentUser = Administrator.Get();
            }
            else
            {
                currentUser = DatabaseUtilities.GetUser(this.User.Identity.Name);
            }

            // populate up to two of the latest announcements preview on the homepage
            List <Announcement> announcements = DatabaseUtilities.GetAnnouncements(currentUser.GroupNumber);

            for (int i = 0; i < 2 && i < announcements.Count; i++)
            {
                // fill the table with the announcement's details
                TableRow  announcementRow       = new TableRow();
                TableCell announcementTitleCell = new TableCell();
                TableCell announcementDateCell  = new TableCell();
                announcementTitleCell.Text = "<a href='AnnouncementView?announcementID=" + announcements[i].ID + "'>" +
                                             announcements[i].Title + "</a>";
                announcementDateCell.Text = announcements[i].CreationDate.ToShortDateString();
                announcementRow.Controls.Add(announcementTitleCell);
                announcementRow.Controls.Add(announcementDateCell);
                AnnouncementTable.Controls.Add(announcementRow);
            }

            // populate the meetings preview on the homepage
            List <Meeting> meetings = DatabaseUtilities.GetMeetingsForGroup(currentUser.GroupNumber);

            for (int i = 0; i < 2 && i < meetings.Count; i++)
            {
                // fill the table with the meeting's details
                TableRow  meetingRow          = new TableRow();
                TableCell meetingLocationCell = new TableCell();
                TableCell meetingDateCell     = new TableCell();
                meetingLocationCell.Text = "<a href='MeetingView?meetingID=" + meetings[i].ID + "'>" +
                                           meetings[i].Location + "</a>";
                meetingDateCell.Text = meetings[i].StartTime.ToShortDateString();

                // add to table
                meetingRow.Controls.Add(meetingLocationCell);
                meetingRow.Controls.Add(meetingDateCell);
                MeetingsTable.Controls.Add(meetingRow);
            }

            // get the latest messages from the chatroom
            Chatroom cr = ChatroomManager.GetChatroom(currentUser.GroupNumber);

            for (int i = 0; i < 2 && i < cr.Messages.Count; i++)
            {
                ChatMessage m       = cr.Messages[cr.Messages.Count - i - 1] as ChatMessage;
                string      content = m.MessageContent;
                // truncate the message for spacing reasons
                if (content.Length >= CHARCOUNT)
                {
                    content = content.Substring(0, CHARCOUNT - 3) + "...";
                }

                // table row and cells
                TableRow  messageRow  = new TableRow();
                TableCell senderCell  = new TableCell();
                TableCell contentCell = new TableCell();

                contentCell.Text = content;
                senderCell.Text  = m.Source.FirstName + " " + m.Source.Surname;

                // add to table
                messageRow.Controls.Add(senderCell);
                messageRow.Controls.Add(contentCell);
                MessageTable.Controls.Add(messageRow);
            }
        }