Exemple #1
0
        public void WorkUnitModel_TimePerSectionTest5()
        {
            var mockBenchmarkService = new Mock <IProteinBenchmarkService>();
            var benchmark            = new ProteinBenchmark {
                FrameTimes = { new ProteinBenchmarkFrameTime {
                                   Duration = TimeSpan.FromMinutes(10)
                               } }
            };

            mockBenchmarkService.Setup(x => x.GetBenchmark(It.IsAny <SlotIdentifier>(), It.IsAny <ProteinBenchmarkIdentifier>())).Returns(benchmark);
            var workUnitModel = CreateWorkUnitModel(null, new WorkUnit(), mockBenchmarkService.Object);

            Assert.AreEqual(TimeSpan.FromMinutes(10), workUnitModel.GetFrameTime(PPDCalculation.LastFrame));
        }
Exemple #2
0
        private static bool BenchmarkMatchesClientIdentifier(ProteinBenchmark b, ClientIdentifier clientIdentifier)
        {
            // most specific, matches ClientIdentifier on Guid first... then Name, Server, and Port
            if (b.SlotIdentifier.ClientIdentifier.Equals(clientIdentifier))
            {
                return(true);
            }

            // less specific, matches ClientIdentifier only on Name, Server, and Port
            if (ClientIdentifier.ProteinBenchmarkEqualityComparer.Equals(b.SlotIdentifier.ClientIdentifier, clientIdentifier))
            {
                return(true);
            }

            return(false);
        }
Exemple #3
0
        public ProteinBenchmark Update(SlotIdentifier slotIdentifier, ProteinBenchmarkIdentifier benchmarkIdentifier, IEnumerable <TimeSpan> frameTimes)
        {
            if (slotIdentifier == SlotIdentifier.AllSlots)
            {
                throw new ArgumentException("Cannot update all client slots.");
            }
            if (frameTimes == null)
            {
                throw new ArgumentNullException(nameof(frameTimes));
            }

            // GetBenchmark() BEFORE entering write lock because it uses a read lock
            var benchmark = GetBenchmark(slotIdentifier, benchmarkIdentifier);

            // write lock
            _cacheLock.EnterWriteLock();
            try
            {
                if (benchmark is null)
                {
                    benchmark = new ProteinBenchmark();
                    DataContainer.Data.Add(benchmark);
                }
                benchmark
                .UpdateFromSlotIdentifier(slotIdentifier)
                .UpdateFromBenchmarkIdentifier(benchmarkIdentifier);

                foreach (var f in frameTimes)
                {
                    benchmark.AddFrameTime(f);
                }
                DataContainer.Write();

                return(benchmark);
            }
            finally
            {
                _cacheLock.ExitWriteLock();
            }
        }
Exemple #4
0
        private static bool BenchmarkMatchesSlotIdentifier(ProteinBenchmark b, SlotIdentifier slotIdentifier)
        {
            // when AllSlots is given, then all SlotIdentifiers match
            if (SlotIdentifier.AllSlots.Equals(slotIdentifier))
            {
                return(true);
            }

            // most specific, matches ClientIdentifier on Guid first... then Name, Server, and Port
            if (b.SlotIdentifier.Equals(slotIdentifier))
            {
                return(true);
            }

            // less specific, matches ClientIdentifier only on Name, Server, and Port
            if (SlotIdentifier.ProteinBenchmarkEqualityComparer.Equals(b.SlotIdentifier, slotIdentifier))
            {
                return(true);
            }

            return(false);
        }
Exemple #5
0
 private static bool BenchmarkMatchesSlotIdentifierAndProject(ProteinBenchmark b, SlotIdentifier slotIdentifier, IEnumerable <int> projects)
 {
     return(projects.Contains(b.ProjectID) && BenchmarkMatchesSlotIdentifier(b, slotIdentifier));
 }
Exemple #6
0
 private static bool BenchmarkMatchesSlotIdentifierAndProject(ProteinBenchmark b, SlotIdentifier slotIdentifier, int projectID)
 {
     return(b.ProjectID.Equals(projectID) && BenchmarkMatchesSlotIdentifier(b, slotIdentifier));
 }