示例#1
0
        public TrayIcon(Connection Connection, User CurrentUser, Room CurrentRoom)
        {
            InitializeComponent();

            this.Connection = Connection;
            this.CurrentUser = CurrentUser;
            this.CurrentRoom = CurrentRoom;

            Connection.Disconnect += Connection_Disconnect;

            MainWindowShown = false;
            AdminWindowShown = false;

            ToolbarIcon = new System.Windows.Forms.NotifyIcon();
            ToolbarIcon.MouseClick += ToolbarIcon_Click;
            ToolbarIcon.Icon = Properties.Resources.ToolbarIcon;
            ToolbarIcon.Visible = true;

            // Construct the context menu so that it contains relevant options for the user

            Menu = new System.Windows.Forms.ContextMenu();
            Menu.MenuItems.Add(new System.Windows.Forms.MenuItem("View Bookings", (s, e) => ToolbarIcon_Click(s, null)));

            // Admins can customise
            if (CurrentUser.Access == AccessMode.Admin)
                Menu.MenuItems.Add(new System.Windows.Forms.MenuItem("Customise system", (s, e) => ShowAdminWindow()));

            // Admins and teachers can exit
            if (CurrentUser.Access == AccessMode.Admin || CurrentUser.Access == AccessMode.Teacher)
                Menu.MenuItems.Add(new System.Windows.Forms.MenuItem("Exit", ExitClick));
            ToolbarIcon.ContextMenu = Menu;

            // Every 30 seconds, fire an event
            Timer = new Timer(TimeSpan.FromSeconds(30).TotalMilliseconds);
            Timer.Elapsed += Timer_Elapsed;
            Timer.Start();

            Timer_Elapsed(null, null); // Fire the timer event immediately
        }
示例#2
0
        public TimetableTile(Booking Booking, TimeSlot Time, Room Room, User CurrentUser)
        {
            // Sets UI bindings to reference this object
            DataContext = this;

            this.Booking = Booking;
            this.Time = Time;
            this.Room = Room;

            // Set the default brightness function to the default
            BrightnessCurve = DefaultBrightnessCurve;

            // Default to the background window colour
            Brush = SystemColors.WindowBrush;
            if (Booking != null) // If there's actually a booking in this slot, use its colour
                Brush = new SolidColorBrush(Booking.Subject.Colour);
            Background = Brush;

            // Initialise the UI
            InitializeComponent();

            // Hook up mouse events
            MouseEnter += TimetableTile_MouseEnter;
            MouseLeave += TimetableTile_MouseLeave;

            // If there's a booking in this slot
            if (Booking != null && CurrentUser != null)
            {
                // If the current user is somehow involved in the booking (either
                // as a student or teacher)
                if (((CurrentUser is Student) && Booking.Students.Any(s => s.Id == CurrentUser.Id)) ||
                    ((CurrentUser is Teacher) && Booking.Teacher.Id == CurrentUser.Id))
                {
                    // Do a simple animation on the tiles to draw attention
                    Storyboard PulseEffect = (Storyboard)Resources["PulseEffect"];
                    PulseEffect.Begin(Outer);
                }
            }
        }
 public UserInformationMessage(User User, Room Room)
 {
     this.User = User;
     this.Room = Room;
 }
示例#4
0
        // Handler for when the server receives a message
        private static void MessageReceived(Connection Sender, Message Msg)
        {
            bool Locked = true;
            Monitor.Enter(Lock);

            // Don't echo changes back to the server - changes made in this
            // function have been sent to us by the server
            ReportModelChanges = false;

            if (Msg is InitialiseMessage)
            {
                // Initialisation of the client - load in the data
                LoadSnapshot((Msg as InitialiseMessage).Snapshot, false);

                // Signal that we've received the initial data
                InitialisedEvent.Set();
            }
            else if (Msg is UserInformationMessage)
            {
                // Information on the User and their Room

                UserInformationMessage m = (Msg as UserInformationMessage);
                User User = m.User;
                Room Room = m.Room;

                if (User == null)
                    throw new ArgumentNullException("Received a null user.");
                if (Room == null)
                    throw new ArgumentNullException("Received a null room.");

                // Acquire references to the actual user/room
                DataSnapshot Frame = TakeSnapshot(false);
                CurrentUser = Frame.Users.SingleOrDefault(u => u.Id == User.Id);
                CurrentRoom = Frame.Rooms.SingleOrDefault(r => r.Id == Room.Id);

                // Signal that we've received the user data
                UserEvent.Set();
            }
            else if (Msg is DataMessage)
            {
                DataMessage Data = (DataMessage)Msg;

                // Get references to linked objects
                using (DataRepository Repo = new DataRepository(false))
                    Data.Item.Expand(Repo);

                // If we're not deleting it, set references to this item
                if (!Data.Delete)
                    Data.Item.Attach();
                else // Otherwise remove references
                    Data.Item.Detach();

                // Store the type of the received data
                Type t = Data.Item.GetType();
                // Get the right table from the dictionary (match received type to key)
                IList Table = Tables.Single(p => t == p.Key || t.IsSubclassOf(p.Key)).Value;

                // Find the index of the item in the table
                int Index = -1;
                for (int x = 0; x < Table.Count; x++)
                {
                    if (((DataModel)Table[x]).Id == Data.Item.Id)
                    {
                        Index = x;
                        break;
                    }
                }

                if (!Data.Delete)
                {
                    if (Index < 0) // Doesn't already exist, add it
                        Table.Add(Data.Item);
                    else // Already exists, update it
                        ((DataModel)Table[Index]).Update(Data.Item);
                }
                else // Delete it
                    Table.RemoveAt(Index);

                // Release the lock
                Monitor.Exit(Lock);
                // Note that we've already released it
                Locked = false;

                // Fire the change of data handler
                DataChanged(Data.Item.GetType());
            }

            ReportModelChanges = true; // Continue reporting changes

            if (Locked) // Release the lock if we haven't already
                Monitor.Exit(Lock);
        }