Esempio n. 1
0
        /// <summary>
        /// Adds latecomers to the current test session
        /// </summary>
        /// <param name="Latecomers">People to add</param>
        public void AddLateComers(List <ClientModel> Latecomers)
        {
            if (!IsTestInProgress)
            {
                return;
            }

            var packageWithTest = DataPackage.TestPackage(CurrentTest);
            var packageWithArgs = DataPackage.StartTestPackage(TestStartupArgs);

            // Based on the arguments set the timer offset
            TestStartupArgs.TimerOffset = CurrentTest.Info.Duration - TimeLeft;

            // Add clients to the test
            foreach (var client in Latecomers)
            {
                ClientsInTest.Add(client);

                IoCServer.Network.Send(client, packageWithTest);

                IoCServer.Network.Send(client, packageWithArgs);

                client.ResetForNewTest(CurrentTest.Questions.Count);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Cleans the test host and prepares it for brand new usage
 /// </summary>
 private void CleanUp()
 {
     // Clean up
     CurrentTest     = null;
     TestStartupArgs = null;
     TimeLeft        = default(TimeSpan);
     Results         = null;
     ClientsInTest.Clear();
     CurrentSessionIdentifier = default(Guid);
 }
Esempio n. 3
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. 4
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. 5
0
        /// <summary>
        /// Sets the clients that will be taking the test
        /// </summary>
        /// <param name="ClientsToAdd">The clients that will take the test</param>
        public void AddClients(List <ClientModel> ClientsToAdd)
        {
            if (IsTestInProgress)
            {
                // Use add latecommers method in this case
                return;
            }

            // Clear the list
            ClientsInTest.Clear();

            foreach (var client in ClientsToAdd)
            {
                if (client.CanStartTest)
                {
                    ClientsInTest.Add(client);
                }
            }
        }
Esempio n. 6
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;
            }
        }