Esempio n. 1
0
        /// <summary>
        /// Fired when the client data is updated
        /// </summary>
        /// <param name="OldModel"></param>
        /// <param name="NewModel"></param>
        private void ServerNetwork_OnClientDataUpdated(ClientModel OldModel, ClientModel NewModel)
        {
            if (IsTestInProgress)
            {
                return;
            }

            // If the client is included in this test update it's model
            if (ClientsInTest.Contains(OldModel))
            {
                NewModel.ResetForNewTest(CurrentTest.Questions.Count);
                ClientsInTest[ClientsInTest.IndexOf(OldModel)] = NewModel;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Fired when a client disconnected from the server
        /// </summary>
        /// <param name="client">The client that has disconnected</param>
        private void OnClientDisconnected(ClientModel client)
        {
            // If the client that has disconnected is the one who isn't taking the test right now, don't do anything
            if (!ClientsInTest.Contains(client))
            {
                return;
            }

            if (IsTestInProgress)
            {
                client.HasConnectionProblem = true;
            }
            else
            {
                ClientsInTest.Remove(client);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Fired when any data is resived from a client
        /// </summary>
        /// <param name="client">The sender client</param>
        /// <param name="dataPackage">The data received from the client</param>
        public void OnDataReceived(ClientModel client, DataPackage dataPackage)
        {
            // If the data is from client we dont care about don't do anything
            if (!ClientsInTest.Contains(client))
            {
                return;
            }

            switch (dataPackage.PackageType)
            {
            case PackageType.ReportStatus:

                // Status package, contains only number of questions the client has done so far
                var content = dataPackage.Content as StatusPackage;
                client.CurrentQuestion = content.CurrentQuestion;

                break;

            case PackageType.ReadyForTest:

                client.CanStartTest = true;
                break;

            case PackageType.ResultForm:

                // Get the content
                var result = dataPackage.Content as ResultFormPackage;

                // Save them in client model
                client.Answers                = result.Answers;
                client.PointsScored           = result.PointsScored;
                client.Mark                   = result.Mark;
                client.QuestionsOrder         = result.QuestionsOrder;
                client.HasResultsBeenReceived = true;

                if (HasEveryClientSentResults())
                {
                    SaveResults();
                    FinishTest();
                }

                else if (OnlyClientsWithConnectionProblemLeft())
                {
                    var vm = new DecisionDialogViewModel()
                    {
                        Title      = "Finishing test",
                        Message    = "Do you want to end the test before time as only users left are these with connection problem?",
                        AcceptText = "Ok",
                        CancelText = "No, wait for them",
                    };

                    IoCServer.UI.ShowMessage(vm);

                    // Stop before time
                    if (vm.UserResponse)
                    {
                        SaveResults();
                        FinishTest();
                    }
                }

                break;
            }
        }