Пример #1
0
        void GetAllParticipants()
        {
            /*
             * var participantVMs = Array.ConvertAll(_repository.Participants.ToArray(),
             *  new Converter<Participant, ParticipantListItemViewModel>(p => new ParticipantListItemViewModel(Mapper.Map<ParticipantModel>(p))));
             * */
            var now       = DateTime.Now;
            int partCount = _repository.Participants.Count();
            List <ParticipantListItemViewModel> participantVMs = new List <ParticipantListItemViewModel>(partCount);

            foreach (var p in _repository.Participants//.Include("VaccinesAdministered").Include("ProtocolViolations").OrderByDescending(dp => dp.Id)
                     .Select(GetParticipantBaseMapExpression()))
            {
                p.StudyCentre = _repository.FindStudyCentre(p.CentreId);
                p.AgeDays     = (now - p.DateTimeBirth).Days;
                var newVm = new ParticipantListItemViewModel(p);
                participantVMs.Add(newVm);
            }

            _ageUpdater = AgeUpdatingMediator.GetService(participants: (from p in participantVMs
                                                                        where p.IsKnownDead != true && p.AgeDays <= ParticipantBaseModel.FollowToAge
                                                                        select(IBirthday) p),
                                                         capacity: partCount);
            _ageUpdater.OnAgeIncrement += OnNewAge;

            AllParticipants = new ListCollectionView(participantVMs)
            {
                CustomSort = new ParticipantIdSortDesc()
            };
            _groupByDataRequired  = true;
            _selectedDataRequired = (DataRequiredOption[])Enum.GetValues(typeof(DataRequiredOption));
            _selectedCentres      = _repository.GetCentresRequiringData();
            SetGrouping();
            //creating dispatchertimer so that screen is rendered before setting up the birthtime updating algorithms
        }
Пример #2
0
 internal static AgeUpdatingService GetService(IEnumerable <IBirthday> participants, int capacity = 4)
 {
     if (_updator == null)
     {
         _updator = new AgeUpdatingService(participants: participants, capacity: capacity);
     }
     return(_updator);
 }
Пример #3
0
 public DataSummaryViewModel(IRepository repository) : base(repository)
 {
     _participantData                          = _repository.GetParticipantSummary();
     ParticipantData                           = new ParticipantSummaryViewModel(_participantData);
     ScreenedPatientData                       = _repository.GetScreenedPatientSummary();
     _repository.ParticipantAdded             += _repository_ParticipantAdded;
     _repository.ParticipantUpdated           += _repository_ParticipantUpdated;
     _repository.ScreenedPatientAdded         += _repository_ScreenedPatientAdded;
     _repository.ProtocolViolationAddOrUpdate += _repository_ProtocolViolationAddOrUpdate;
     _ageService = AgeUpdatingMediator.GetService(repository);
     _ageService.OnAgeIncrement += OnNewAge;
 }
Пример #4
0
        void TestParticipantsNotStartingTimer(params DateTime[] birthDateTimes)
        {
            var mockTimer = new Mock <IDispatcherTimer>(MockBehavior.Strict);

            mockTimer.SetupProperty(m => m.Interval);
            mockTimer.Setup(m => m.Start());
            mockTimer.Setup(m => m.Stop());
            var moqArgs      = new  MoqTimerEventArgs(true);
            var participants = GetParticipants(moqArgs, birthDateTimes);
            var ageService   = new AgeUpdatingService(participants, mockTimer.Object);

            mockTimer.Verify(m => m.Start(), Times.Never);
        }
Пример #5
0
        public void TestAgeUpdatingStartOnAdd()
        {
            var moqArgs   = new MoqTimerEventArgs(true);
            var mockTimer = new Mock <IDispatcherTimer>(MockBehavior.Strict);

            mockTimer.SetupProperty(m => m.Interval);
            mockTimer.Setup(m => m.Start()).Verifiable();
            mockTimer.Setup(m => m.Stop()).Verifiable();
            IDispatcherTimer timer = mockTimer.Object;

            var ageService = new AgeUpdatingService(new ParticipantListItemViewModel[0], timer);

            mockTimer.Verify(m => m.Start(), Times.Never);

            TimeSpan toDob = TimeSpan.FromMinutes(-10);
            var      p     = new ParticipantListItemViewModel(
                new ParticipantBaseModel
            {
                Id            = 1,
                DateTimeBirth = moqArgs.StartAt + toDob
            });

            TimeSpan expectedInterval = TimeSpan.FromDays(1) + toDob;
            TimeSpan tolerance        = TimeSpan.FromSeconds(defaultSecsTolerance);

            mockTimer.SetupSet(m => m.Interval = It.IsAny <TimeSpan>()).Callback <TimeSpan>(i =>
            {
                string usrMsg = string.Format(intervalLogTemplate, i, expectedInterval, tolerance);
                if (i < expectedInterval - tolerance || i > expectedInterval + tolerance)
                {
                    throw new ArgumentOutOfRangeException("Interval", usrMsg);
                }
                else
                {
                    Console.WriteLine(usrMsg);
                }
            });
            ageService.AddParticipant(p);
            mockTimer.Verify(m => m.Start(), Times.Once);

            TimeSpan laterDayversary = TimeSpan.FromMinutes(-5);

            p = new ParticipantListItemViewModel(
                new ParticipantBaseModel
            {
                Id            = 2,
                DateTimeBirth = moqArgs.StartAt + laterDayversary
            });
            ageService.AddParticipant(p);

            toDob = TimeSpan.FromMinutes(-30);
            p     = new ParticipantListItemViewModel(
                new ParticipantBaseModel
            {
                Id            = 2,
                DateTimeBirth = moqArgs.StartAt + toDob
            });
            expectedInterval = TimeSpan.FromDays(1) + toDob;

            ageService.AddParticipant(p);

            toDob = TimeSpan.FromDays(-1).Add(TimeSpan.FromMinutes(5));
            p     = new ParticipantListItemViewModel(
                new ParticipantBaseModel
            {
                Id            = 2,
                DateTimeBirth = moqArgs.StartAt + toDob
            });
            expectedInterval = TimeSpan.FromDays(1) + toDob;

            ageService.AddParticipant(p);
        }
Пример #6
0
        MyMoq TestAgeUpdatingSetInterval(params DateTime[] birthDateTimes)
        {
            if (birthDateTimes == null || birthDateTimes.Length < 2)
            {
                throw new ArgumentException("must include at least 2 birthDateTimes");
            }

            var moqArgs      = new MoqTimerEventArgs(true);
            var participants = GetParticipants(moqArgs, birthDateTimes);

            var expectedTimesFromNow = TimesFromNow(birthDateTimes, moqArgs.StartAt);

            var mockTimer = new Mock <IDispatcherTimer>(MockBehavior.Strict);

            mockTimer.SetupProperty(m => m.Interval);
            mockTimer.Setup(m => m.Start());
            mockTimer.Setup(m => m.Stop());
            TimeSpan expectedInterval = expectedTimesFromNow[0];
            TimeSpan tolerance        = TimeSpan.FromSeconds(defaultSecsTolerance);
            bool     requiresInterval = true;

            mockTimer.SetupSet(m => m.Interval = It.IsAny <TimeSpan>()).Callback <TimeSpan>(i =>
            {
                string usrMsg = string.Format(intervalLogTemplate, i, expectedInterval, tolerance);
                if (requiresInterval && (i < expectedInterval - tolerance || i > expectedInterval + tolerance))
                {
                    throw new ArgumentOutOfRangeException("Interval", usrMsg);
                }
                else
                {
                    Console.WriteLine(usrMsg);
                }
            });
            IDispatcherTimer timer = mockTimer.Object;

            Console.WriteLine("instantiating AgeUpdatingService");
            var ageService = new AgeUpdatingService(participants, timer);

            Console.WriteLine("finished instantiation");
            mockTimer.Verify(m => m.Start(), Times.AtLeastOnce);

            Action <TimeSpan, TimeSpan> validateIntervals = new Action <TimeSpan, TimeSpan>((last, curr) => {
                if (curr.Ticks > 0)
                {
                    moqArgs.StartAt             += last;
                    expectedInterval             = curr;
                    mockTimer.Raise(m => m.Tick += null, moqArgs);
                }
            });

            moqArgs.StartAt += expectedTimesFromNow.First(); //will have been set during instantiation
            expectedTimesFromNow.AggregatePairSelect((prev, cur) => cur - prev)
            .Where(t => t.Ticks != 0)
            .AggregatePairForEach(new TimeSpan(), validateIntervals);
            requiresInterval             = false;
            mockTimer.Raise(m => m.Tick += null, moqArgs);

            Console.WriteLine("Adding new participants");
            moqArgs.StartAt = DateTime.Now;
            foreach (var addedInterval in (new int[] { 10, -10 }).Select(i => TimeSpan.FromSeconds(i)))
            {
                participants.Add(new ParticipantListItemViewModel(
                                     new ParticipantBaseModel
                {
                    Id            = participants.Count + 1,
                    DateTimeBirth = moqArgs.StartAt - TimeSpan.FromDays(1) + addedInterval
                }));
                ageService.AddParticipant(participants[participants.Count - 1]);
            }
            requiresInterval = true;
            moqArgs.StartAt += TimeSpan.FromSeconds(10);

            expectedTimesFromNow = TimesFromNow(from p in participants where p.AgeDays <= 28 select p.DateTimeBirth, moqArgs.StartAt);

            expectedTimesFromNow.AggregatePairSelect(new TimeSpan(), (prev, cur) => cur - prev)
            .Where(t => t.Ticks != 0)
            .AggregatePairForEach(new TimeSpan(), validateIntervals);

            requiresInterval             = false;
            mockTimer.Raise(m => m.Tick += null, moqArgs);

            return(new MyMoq {
                AgeService = ageService, Moq = mockTimer
            });
        }