Example #1
0
 void IBL.removeTest(int testNumber)
 {
     try
     {
         if (testNumber < Configuration.BeginningSerialTestNumber || testNumber > 99999999)
         {
             throw new InvalidTestNumberException("Invalid test number");
         }
         DO.Test  DOTest          = dlObject.getTest(testNumber);
         DateTime testDateAndTime = DOTest.TestDate.AddHours(DOTest.TestTime);
         //has the test done already?
         if (testDateAndTime <= new DateTime().SystemNow())
         {
             throw new TestCannotBeDeletedException("the test has already done and cannot be deleted");
         }
         //are there enough days to the date to abort the test?
         if (testDateAndTime.AddDays(-Configuration.DaysBeforeTestATestCanBeDeleted) <= new DateTime().SystemNow())
         {
             throw new TestCannotBeDeletedException("You may not abort a test less then " + Configuration.DaysBeforeTestATestCanBeDeleted + " days before its time.");
         }
         dlObject.removeTest(testNumber);
     }
     catch (Exception exception)
     {
         throw exception.ToBOException();
     }
 }
Example #2
0
        void IBL.updateTest(int testNumber, TesterTest test, int testerID)
        {
            try
            {
                if (testNumber < Configuration.BeginningSerialTestNumber || testNumber > 99999999)
                {
                    throw new InvalidTestNumberException("Invalid test number.\n");
                }

                //to do: make sure the tester inserted all the grades fields in his feedback
                DO.Test originalTest = dlObject.getTest(testNumber);
                //to do: update the coming test fields - date, tester, exitAddress ect.
                //is the test over?
                if (new DateTime().SystemNow() < originalTest.TestDate.AddHours(originalTest.TestTime).AddMinutes(40))
                {
                    throw new FeedbackBeforeTestEndsException("You cannot give feedback before the test ends!\n");
                }
                //is the test done and got the grades already?
                if (originalTest.TestAlreadyDoneAndSealed)
                {
                    throw new TestHasBeenDoneAndSealedException("You cannot change details of a test after it has already got grades.\n");
                }
                //does the feedback make sense?
                if (!gradesMakeSense(test))
                {
                    throw new FeedbackMakesNoSenseException("Test feedback details do not make sense.\n");
                }
                test.TestAlreadyDoneAndSealed = true;
                dlObject.updateTest(testNumber, test.ToDOTest(testerID));
            }
            catch (Exception exception)
            {
                throw exception.ToBOException();
            }
        }
Example #3
0
 private void addTesterDetails(DO.Test doTestSorce, Test boTestToUpdate)
 {
     try
     {
         DO.Tester      tester        = dlObject.getTester(doTestSorce.TesterID);
         ExternalTester testerDetails = new ExternalTester(tester.ToBOTester());
         boTestToUpdate.Tester = testerDetails;
     }
     catch (Exception exception)
     {
         throw exception.ToBOException();
     }
 }
Example #4
0
 public Test(DO.Test other)
 {
     TestId               = other.TestId;
     exTrainee            = new ExternalTrainee(other.TraineeId); /////////////////////////////////////
     exTester             = new ExternalTester(other.TesterId);   ////////////////////////////////////////
     dateOfTest           = other.DateOfTest;
     hourOfTest           = other.HourOfTest;
     carType              = (CarTypeEnum)other.CarType;
     startTestAddress     = new Address(other.StartTestAddress.City, other.StartTestAddress.Street, other.StartTestAddress.BuildingNumber);
     distanceKeeping      = other.DistanceKeeping;
     reverseParking       = other.ReverseParking;
     mirrorsCheck         = other.MirrorsCheck;
     signals              = other.Signals;
     correctSpeed         = other.CorrectSpeed;
     isPassed             = other.IsPassed;
     testerNotes          = other.TesterNotes;
     isTesterUpdateStatus = other.IsTesterUpdateStatus;
 }
Example #5
0
        void IBL.addTestWithFoundTester(Trainee trainee, DateTime date, int time, Address exitAddress, Tester foundTester)
        {
            ExternalTester tester = new ExternalTester(foundTester);
            Test           test   = new Test(
                0,
                tester,
                trainee.ID,
                trainee.FirstName + " " + trainee.LastName,
                date,
                time,
                exitAddress);

            DO.Test testToAdd       = test.ToDOTest();
            int     fixedTestNumber = dlObject.addTest(testToAdd);

            trainee.Tests.Add(
                new TraineeTest(dlObject.getTest(fixedTestNumber).ToBOTest(),
                                new ExternalTrainee(trainee)));
        }
Example #6
0
 public static BO.Test CreateBOTest(DO.Test other)
 {
     BO.Test test = new Test(other.TestId);
     test.ExTrainee            = new ExternalTrainee(other.TraineeId); /////////////////////////////////////
     test.ExTester             = new ExternalTester(other.TesterId);   ////////////////////////////////////////
     test.DateOfTest           = other.DateOfTest;
     test.HourOfTest           = other.HourOfTest;
     test.CarType              = (CarTypeEnum)other.CarType;
     test.StartTestAddress     = new Address(other.StartTestAddress.City, other.StartTestAddress.Street, other.StartTestAddress.BuildingNumber);
     test.DistanceKeeping      = other.DistanceKeeping;
     test.ReverseParking       = other.ReverseParking;
     test.MirrorsCheck         = other.MirrorsCheck;
     test.Signals              = other.Signals;
     test.CorrectSpeed         = other.CorrectSpeed;
     test.IsPassed             = other.IsPassed;
     test.TesterNotes          = other.TesterNotes;
     test.IsTesterUpdateStatus = other.IsTesterUpdateStatus;
     test.IsTestAborted        = other.IsTestAborted;
     return(test);
 }
Example #7
0
        Test IBL.getTest(int testNumber)
        {
            try
            {
                if (testNumber < Configuration.BeginningSerialTestNumber || testNumber > 99999999)
                {
                    throw new InvalidTestNumberException("Invalid test number");
                }

                DO.Test doTestSource = dlObject.getTest(testNumber);
                Test    test         = doTestSource.ToBOTest();
                addTesterDetails(doTestSource, test);
                addTraineeName(test);
                return(test);
            }
            catch (Exception exception)
            {
                throw exception.ToBOException();
            }
        }
Example #8
0
        public static DO.Test CreateDOTest(BO.Test other)
        {
            var test = new DO.Test();

            test.TesterId             = other.ExTester.Id;
            test.TraineeId            = other.ExTrainee.Id;
            test.DateOfTest           = other.DateOfTest;
            test.HourOfTest           = other.HourOfTest;
            test.StartTestAddress     = new DO.Address(other.StartTestAddress.City, other.StartTestAddress.Street, other.StartTestAddress.BuildingNumber);
            test.CarType              = (DO.CarTypeEnum)other.CarType;
            test.DistanceKeeping      = other.DistanceKeeping;
            test.ReverseParking       = other.ReverseParking;
            test.MirrorsCheck         = other.MirrorsCheck;
            test.Signals              = other.Signals;
            test.CorrectSpeed         = other.CorrectSpeed;
            test.IsPassed             = other.IsPassed;
            test.TesterNotes          = other.TesterNotes;
            test.IsTesterUpdateStatus = other.IsTesterUpdateStatus;
            return(test);
        }
 public static DO.Test ToDOTest(this TesterTest BOTesterTest, int testerID)
 {
     DO.Test converted = new DO.Test(
         BOTesterTest.TestNumber,
         testerID,
         BOTesterTest.TraineeID,
         BOTesterTest.TestDate,
         BOTesterTest.TestTime,
         BOTesterTest.ExitAddress.ToDOAddress(),
         BOTesterTest.TestAlreadyDoneAndSealed,
         BOTesterTest.DistanceKeeping,
         BOTesterTest.ReverseParking,
         BOTesterTest.LookingAtMirrors,
         BOTesterTest.SignalsUsage,
         BOTesterTest.PriorityGiving,
         BOTesterTest.SpeedKeeping,
         BOTesterTest.TestScore,
         BOTesterTest.TestersNote
         );
     return(converted);
 }
        public static Test ToBOTest(this DO.Test DOTest)
        {
            Tester  tester    = dl.getTester(DOTest.TesterID).ToBOTester();
            Trainee trainee   = dl.getTrainee(DOTest.TraineeID).ToBOTrainee();
            Test    converted = new Test(
                DOTest.TestNumber,
                new ExternalTester(tester),
                DOTest.TraineeID,
                trainee.FirstName + " " + trainee.LastName,
                DOTest.TestDate,
                DOTest.TestTime,
                DOTest.ExitAddress.ToBOAddress(),
                DOTest.TestAlreadyDoneAndSealed,
                DOTest.DistanceKeeping,
                DOTest.ReverseParking,
                DOTest.LookingAtMirrors,
                DOTest.SignalsUsage,
                DOTest.PriorityGiving,
                DOTest.SpeedKeeping,
                DOTest.TestScore,
                DOTest.TestersNote);

            return(converted);
        }
Example #11
0
        private void AddTestWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                BackgroundWorker worker      = sender as BackgroundWorker;
                List <Object>    parms       = e.Argument as List <Object>;
                Address          exitAddress = (Address)parms[0];
                List <DO.Tester> relevants   = parms[1] as List <DO.Tester>;
                DateTime         date        = (DateTime)parms[2];
                int     time    = (int)parms[3];
                Trainee trainee = (Trainee)parms[4];

                List <Tester> relevantAndCloseTesters = relevants.
                                                        Where(tester => distance(tester.Address.ToBOAddress(), exitAddress, worker) <= tester.MaxDistanceFromAddress).
                                                        Select(x => x.ToBOTester()).ToList();
                if (worker.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }
                foreach (Tester BOtester in relevantAndCloseTesters)
                {
                    addListOfTests(BOtester);
                    addTesterSchedule(BOtester);
                }

                if (relevantAndCloseTesters.Any() == false)
                {
                    throw new NoTesterCloseEnoughException("Sorry, we have no tester close enough to the asked exit address, please choose another address.\n");
                }
                if (worker.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }
                ExternalTester foundTester = getAvailableTester(relevantAndCloseTesters, date, time, trainee, exitAddress, worker);
                Test           test        = new Test(
                    0,
                    foundTester,
                    trainee.ID,
                    trainee.FirstName + " " + trainee.LastName,
                    date,
                    time,
                    exitAddress);
                if (worker.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }
                DO.Test testToAdd       = test.ToDOTest();
                int     fixedTestNumber = dlObject.addTest(testToAdd);
                trainee.Tests.Add(
                    new TraineeTest(dlObject.getTest(fixedTestNumber).ToBOTest(),
                                    new ExternalTrainee(trainee)));
                e.Result = fixedTestNumber;
            }
            catch (Exception ex)
            {
                if (ex is OperationCanceledException)
                {
                    e.Cancel = true;
                }
                e.Result = ex.ToBOException();
            }
        }