public void ProteinBenchmarkService_Update_AddsFrameTimes()
        {
            var       guid      = Guid.NewGuid();
            const int slotID    = 0;
            const int projectID = 9039;

            var container = new ProteinBenchmarkDataContainer();

            container.Data.Add(new ProteinBenchmark {
                SourceGuid = guid, SourceSlotID = slotID, ProjectID = projectID
            });
            var benchmarkService = new ProteinBenchmarkService(container);

            var slotIdentifier = new SlotIdentifier(new ClientIdentifier(null, null, ClientSettings.NoPort, guid), slotID);
            var benchmarkIdentifier = new ProteinBenchmarkIdentifier(projectID);
            var frameTimes = new[] { 1.0, 1.2, 1.1 }.Select(TimeSpan.FromMinutes);

            // Act
            var benchmark = benchmarkService.Update(slotIdentifier, benchmarkIdentifier, frameTimes);

            // Assert
            Assert.AreEqual(1, container.Data.Count);
            Assert.IsNotNull(benchmark);
            Assert.AreEqual(3, benchmark.FrameTimes.Count);
            Assert.AreEqual(TimeSpan.FromMinutes(1.1), benchmark.FrameTimes[0].Duration);
            Assert.AreEqual(TimeSpan.FromMinutes(1.2), benchmark.FrameTimes[1].Duration);
            Assert.AreEqual(TimeSpan.FromMinutes(1.0), benchmark.FrameTimes[2].Duration);
        }
        public void ProteinBenchmarkService_GetBenchmark_BenchmarkWithGuidMatchesSlotIdentifierByGuid()
        {
            var       guid      = Guid.NewGuid();
            const int slotID    = 0;
            const int projectID = 9039;

            var container = new ProteinBenchmarkDataContainer();

            container.Data.Add(new ProteinBenchmark
            {
                SourceName   = "Foo",
                SourcePath   = "192.168.1.194:36330",
                SourceGuid   = guid,
                SourceSlotID = slotID,
                ProjectID    = projectID,
                FrameTimes   = new[] { 1.4, 1.6, 1.5 }.Select(ProteinBenchmarkFrameTime.FromMinutes).ToList()
            });
            var benchmarkService = new ProteinBenchmarkService(container);

            var slotIdentifier      = new SlotIdentifier(new ClientIdentifier("Bar", "192.168.1.200", 46330, guid), slotID);
            var benchmarkIdentifier = new ProteinBenchmarkIdentifier(projectID);

            // Act
            var benchmark = benchmarkService.GetBenchmark(slotIdentifier, benchmarkIdentifier);

            // Assert
            Assert.IsNotNull(benchmark);
            Assert.AreEqual(slotIdentifier, benchmark.SlotIdentifier);
            Assert.AreEqual(benchmarkIdentifier, benchmark.BenchmarkIdentifier);
        }
        public void ProteinBenchmarkService_Update_BenchmarkWithoutProcessorAndThreadsMatchesBenchmarkIdentifierByProjectID()
        {
            const int projectID = 9039;

            var container      = new ProteinBenchmarkDataContainer();
            var slotIdentifier = new SlotIdentifier(new ClientIdentifier("Foo", "192.168.1.194", ClientSettings.DefaultPort, Guid.NewGuid()), 0);

            container.Data.Add(new ProteinBenchmark {
                ProjectID = projectID
            }
                               .UpdateFromSlotIdentifier(slotIdentifier));
            var benchmarkService = new ProteinBenchmarkService(container);

            var benchmarkIdentifier = new ProteinBenchmarkIdentifier(projectID, Processor, Threads);
            var frameTimes = new[] { 1.0, 1.2, 1.1 }.Select(TimeSpan.FromMinutes);

            // Act
            var benchmark = benchmarkService.Update(slotIdentifier, benchmarkIdentifier, frameTimes);

            // Assert
            Assert.AreEqual(1, container.Data.Count);
            Assert.IsNotNull(benchmark);
            Assert.AreEqual(slotIdentifier, benchmark.SlotIdentifier);
            Assert.AreEqual(benchmarkIdentifier, benchmark.BenchmarkIdentifier);

            var benchmarkFrameTimes = benchmark.FrameTimes.Take(3).ToList();

            Assert.AreEqual(TimeSpan.FromMinutes(1.1), benchmarkFrameTimes[0].Duration);
            Assert.AreEqual(TimeSpan.FromMinutes(1.2), benchmarkFrameTimes[1].Duration);
            Assert.AreEqual(TimeSpan.FromMinutes(1.0), benchmarkFrameTimes[2].Duration);
        }
        public void ProteinBenchmarkService_GetBenchmark_BenchmarkWithoutGuidMatchesSlotIdentifierByNameAndPath()
        {
            var       guid      = Guid.NewGuid();
            const int slotID    = 0;
            const int projectID = 9039;

            var container = new ProteinBenchmarkDataContainer();

            container.Data.Add(new ProteinBenchmark
            {
                SourceName   = "Foo",
                SourcePath   = "192.168.1.194:36330",
                SourceGuid   = Guid.Empty,
                SourceSlotID = slotID,
                ProjectID    = projectID,
                FrameTimes   = new[] { 1.4, 1.6, 1.5 }.Select(ProteinBenchmarkFrameTime.FromMinutes).ToList()
            });
            var benchmarkService = new ProteinBenchmarkService(container);

            var slotIdentifier      = new SlotIdentifier(new ClientIdentifier("Foo", "192.168.1.194", ClientSettings.DefaultPort, guid), slotID);
            var benchmarkIdentifier = new ProteinBenchmarkIdentifier(projectID);

            // Act
            var benchmark = benchmarkService.GetBenchmark(slotIdentifier, benchmarkIdentifier);

            // Assert
            Assert.IsNotNull(benchmark);
            Assert.AreEqual(slotIdentifier.ClientIdentifier.Name, benchmark.SourceName);
            Assert.AreEqual(slotIdentifier.ClientIdentifier.ToServerPortString(), benchmark.SourcePath);
            Assert.AreNotEqual(slotIdentifier.ClientIdentifier.Guid, benchmark.SourceGuid);
            Assert.AreEqual(slotIdentifier.SlotID, benchmark.SourceSlotID);
            Assert.AreEqual(benchmarkIdentifier, benchmark.BenchmarkIdentifier);
        }
        public void ProteinBenchmarkService_GetBenchmark_BenchmarkWithProcessorAndThreadsMatchesBenchmarkIdentifierByProjectIDAndProcessorAndThreads()
        {
            const int projectID = 9039;

            var container      = new ProteinBenchmarkDataContainer();
            var slotIdentifier = new SlotIdentifier(new ClientIdentifier("Foo", "192.168.1.194", ClientSettings.DefaultPort, Guid.NewGuid()), 0);

            container.Data.Add(new ProteinBenchmark {
                ProjectID = projectID, Processor = Processor, Threads = 12
            }
                               .UpdateFromSlotIdentifier(slotIdentifier));
            container.Data.Add(new ProteinBenchmark {
                ProjectID = projectID, Processor = Processor, Threads = Threads
            }
                               .UpdateFromSlotIdentifier(slotIdentifier));
            var benchmarkService = new ProteinBenchmarkService(container);

            var benchmarkIdentifier = new ProteinBenchmarkIdentifier(projectID, Processor, Threads);

            // Act
            var benchmark = benchmarkService.GetBenchmark(slotIdentifier, benchmarkIdentifier);

            // Assert
            Assert.IsNotNull(benchmark);
            Assert.AreSame(container.Data[1], benchmark);
            Assert.AreEqual(slotIdentifier, benchmark.SlotIdentifier);
            Assert.AreEqual(benchmarkIdentifier, benchmark.BenchmarkIdentifier);
        }
Example #6
0
    public override bool CanFit(Pickupable toCheck, SlotIdentifier inSlot)
    {
        Logger.LogTraceFormat("Checking if {0} can fit in {1}", Category.Inventory, toCheck.name, inSlot);
        //which type of slot are we checking
        if (inSlot.SlotIdentifierType == SlotIdentifierType.Indexed)
        {
            if (IndexedSlotCapacity == null)
            {
                Logger.LogTrace("Indexed slot capacity not defined. Defaulting to no fit.", Category.Inventory);
                return(false);
            }
            return(IndexedSlotCapacity.CanFit(toCheck));
        }
        else
        {
            NamedDefinedCapacityEntry entry = NamedSlotCapacity.FirstOrDefault(nsc => nsc.NamedSlot == inSlot.NamedSlot);
            if (entry == null || entry.Capacity == null)
            {
                Logger.LogTraceFormat("Slot capacity not defined for {0}. Defaulting to no fit.", Category.Inventory, inSlot.NamedSlot);
                return(false);
            }

            return(entry.Capacity.CanFit(toCheck));
        }
    }
Example #7
0
    /// <summary>
    /// Gets the specified slot from the specified storage. Null if this item storage does not have
    /// a slot with the given identifier.
    /// </summary>
    /// <param name="itemStorage"></param>
    /// <param name="slotIdentifier"></param>
    /// <returns></returns>
    public static ItemSlot Get(ItemStorage itemStorage, SlotIdentifier slotIdentifier)
    {
        if (!itemStorage.HasSlot(slotIdentifier))
        {
            return(null);
        }

        var instanceID = itemStorage.GetInstanceID();

        slots.TryGetValue(instanceID, out var dict);
        if (dict == null)
        {
            dict = new Dictionary <SlotIdentifier, ItemSlot>();
            slots.Add(instanceID, dict);
        }

        dict.TryGetValue(slotIdentifier, out var slot);
        if (slot == null)
        {
            slot = new ItemSlot(itemStorage, slotIdentifier);
            dict.Add(slotIdentifier, slot);
        }

        return(slot);
    }
        public void ProteinBenchmarkService_Update_CreatesNewBenchmark()
        {
            // Arrange
            using (var artifacts = new ArtifactFolder())
            {
                var container           = CreateTestDataContainer(artifacts.GetRandomFilePath());
                int containerCount      = container.Data.Count;
                var benchmarkService    = new ProteinBenchmarkService(container);
                var clientGuid          = Guid.NewGuid();
                var slotIdentifier      = new SlotIdentifier(new ClientIdentifier("New Client", "10.9.8.1", ClientSettings.DefaultPort, clientGuid), 0);
                var benchmarkIdentifier = new ProteinBenchmarkIdentifier(Int32.MaxValue, Processor, Threads);
                var frameTimes          = new[]
                {
                    TimeSpan.FromMinutes(1.0),
                    TimeSpan.FromMinutes(1.2),
                    TimeSpan.FromMinutes(1.1)
                };
                // Act
                benchmarkService.Update(slotIdentifier, benchmarkIdentifier, frameTimes);
                // Assert
                Assert.AreEqual(containerCount + 1, container.Data.Count);
                var benchmark = benchmarkService.GetBenchmark(slotIdentifier, benchmarkIdentifier);
                Assert.IsNotNull(benchmark);
                Assert.AreEqual(slotIdentifier, benchmark.SlotIdentifier);
                Assert.AreEqual(clientGuid, benchmark.SlotIdentifier.ClientIdentifier.Guid);
                Assert.AreEqual(benchmarkIdentifier, benchmark.BenchmarkIdentifier);

                Assert.AreEqual(3, benchmark.FrameTimes.Count);
                Assert.AreEqual(TimeSpan.FromMinutes(1.1), benchmark.FrameTimes[0].Duration);
                Assert.AreEqual(TimeSpan.FromMinutes(1.2), benchmark.FrameTimes[1].Duration);
                Assert.AreEqual(TimeSpan.FromMinutes(1.0), benchmark.FrameTimes[2].Duration);
            }
        }
    /// <summary>
    ///
    /// </summary>
    /// <param name="slotIdentifier"></param>
    /// <returns>true iff this item storage has the slot with the specified identifier</returns>
    public bool HasSlot(SlotIdentifier slotIdentifier)
    {
        if (definedSlots == null)
        {
            CacheDefinedSlots();
        }

        return(definedSlots.Contains(slotIdentifier));
    }
Example #10
0
    /// <summary>
    /// Gets the slot identifier for a particular named slot
    /// </summary>
    /// <param name="namedSlot"></param>
    /// <returns></returns>
    public static SlotIdentifier Named(NamedSlot namedSlot)
    {
        namedIdentifiers.TryGetValue(namedSlot, out var slotID);
        if (slotID == null)
        {
            slotID = new SlotIdentifier(namedSlot, -1, SlotIdentifierType.Named);
            namedIdentifiers.Add(namedSlot, slotID);
        }

        return(slotID);
    }
Example #11
0
    /// <summary>
    /// Gets the slot identifier for an particular indexed slot.
    /// </summary>
    /// <param name="slotIndex"></param>
    /// <returns></returns>
    public static SlotIdentifier Indexed(int slotIndex)
    {
        indexedIdentifiers.TryGetValue(slotIndex, out var slotID);
        if (slotID == null)
        {
            slotID = new SlotIdentifier(null, slotIndex, SlotIdentifierType.Indexed);
            indexedIdentifiers.Add(slotIndex, slotID);
        }

        return(slotID);
    }
Example #12
0
 public ICollection <ProteinBenchmark> GetBenchmarks(SlotIdentifier slotIdentifier, IEnumerable <int> projects)
 {
     _cacheLock.EnterReadLock();
     try
     {
         return(DataContainer.Data.FindAll(b => BenchmarkMatchesSlotIdentifierAndProject(b, slotIdentifier, projects)));
     }
     finally
     {
         _cacheLock.ExitReadLock();
     }
 }
Example #13
0
 public ICollection <int> GetBenchmarkProjects(SlotIdentifier slotIdentifier)
 {
     _cacheLock.EnterReadLock();
     try
     {
         return(DataContainer.Data.Where(b => BenchmarkMatchesSlotIdentifier(b, slotIdentifier))
                .Select(b => b.ProjectID).Distinct().OrderBy(p => p).ToList());
     }
     finally
     {
         _cacheLock.ExitReadLock();
     }
 }
Example #14
0
 public ProteinBenchmark GetBenchmark(SlotIdentifier slotIdentifier, ProteinBenchmarkIdentifier benchmarkIdentifier)
 {
     _cacheLock.EnterReadLock();
     try
     {
         var benchmarks = DataContainer.Data.FindAll(b => BenchmarkMatchesSlotIdentifier(b, slotIdentifier));
         return(GetBenchmark(benchmarks, benchmarkIdentifier));
     }
     finally
     {
         _cacheLock.ExitReadLock();
     }
 }
Example #15
0
 public void RemoveAll(SlotIdentifier slotIdentifier, int projectID)
 {
     _cacheLock.EnterWriteLock();
     try
     {
         DataContainer.Data.RemoveAll(b => BenchmarkMatchesSlotIdentifierAndProject(b, slotIdentifier, projectID));
         DataContainer.Write();
     }
     finally
     {
         _cacheLock.ExitWriteLock();
     }
 }
Example #16
0
        public void RemoveAll(SlotIdentifier slotIdentifier)
        {
            if (slotIdentifier == SlotIdentifier.AllSlots)
            {
                throw new ArgumentException("Cannot remove all client slots.");
            }

            _cacheLock.EnterWriteLock();
            try
            {
                DataContainer.Data.RemoveAll(b => BenchmarkMatchesSlotIdentifier(b, slotIdentifier));
                DataContainer.Write();
            }
            finally
            {
                _cacheLock.ExitWriteLock();
            }
        }
Example #17
0
        public void UpdateMinimumFrameTime(SlotIdentifier slotIdentifier, int projectID)
        {
            // GetBenchmarks() BEFORE entering write lock because it uses a read lock
            IEnumerable <ProteinBenchmark> benchmarks = GetBenchmarks(slotIdentifier, projectID);

            // write lock
            _cacheLock.EnterWriteLock();
            try
            {
                foreach (var b in benchmarks)
                {
                    b.UpdateMinimumFrameTime();
                }
                DataContainer.Write();
            }
            finally
            {
                _cacheLock.ExitWriteLock();
            }
        }
Example #18
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();
            }
        }
Example #19
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);
        }
        public void ProteinBenchmarkService_Update_BenchmarkWithoutGuidMatchesSlotIdentifierByNameAndPath()
        {
            var       guid      = Guid.NewGuid();
            const int slotID    = 0;
            const int projectID = 9039;

            var container = new ProteinBenchmarkDataContainer();

            container.Data.Add(new ProteinBenchmark
            {
                SourceName   = "Foo",
                SourcePath   = "192.168.1.194:36330",
                SourceGuid   = Guid.Empty,
                SourceSlotID = slotID,
                ProjectID    = projectID,
                FrameTimes   = new[] { 1.4, 1.6, 1.5 }.Select(ProteinBenchmarkFrameTime.FromMinutes).ToList()
            });
            var benchmarkService = new ProteinBenchmarkService(container);

            var slotIdentifier = new SlotIdentifier(new ClientIdentifier("Foo", "192.168.1.194", ClientSettings.DefaultPort, guid), slotID);
            var benchmarkIdentifier = new ProteinBenchmarkIdentifier(projectID);
            var frameTimes = new[] { 1.0, 1.2, 1.1 }.Select(TimeSpan.FromMinutes);

            // Act
            var benchmark = benchmarkService.Update(slotIdentifier, benchmarkIdentifier, frameTimes);

            // Assert
            Assert.AreEqual(1, container.Data.Count);
            Assert.IsNotNull(benchmark);
            Assert.AreEqual(slotIdentifier, benchmark.SlotIdentifier);
            Assert.AreEqual(benchmarkIdentifier, benchmark.BenchmarkIdentifier);

            var benchmarkFrameTimes = benchmark.FrameTimes.Take(3).ToList();

            Assert.AreEqual(TimeSpan.FromMinutes(1.1), benchmarkFrameTimes[0].Duration);
            Assert.AreEqual(TimeSpan.FromMinutes(1.2), benchmarkFrameTimes[1].Duration);
            Assert.AreEqual(TimeSpan.FromMinutes(1.0), benchmarkFrameTimes[2].Duration);
        }
Example #21
0
 public ProteinBenchmark GetBenchmark(SlotIdentifier slotIdentifier, ProteinBenchmarkIdentifier benchmarkIdentifier)
 {
     return(null);
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="named"></param>
 /// <returns>the item slot from this storage, null if this item storage doesn't have this slot</returns>
 public ItemSlot GetItemSlot(SlotIdentifier named)
 {
     return(ItemSlot.Get(this, named));
 }
Example #23
0
 public ICollection <ProteinBenchmark> GetBenchmarks(SlotIdentifier slotIdentifier, IEnumerable <int> projects)
 {
     return(new List <ProteinBenchmark>());
 }
Example #24
0
 private ItemSlot(ItemStorage itemStorage, SlotIdentifier slotIdentifier)
 {
     this.itemStorage      = itemStorage;
     this.itemStorageNetId = itemStorage.GetInstanceID();
     this.slotIdentifier   = slotIdentifier;
 }
Example #25
0
 /// <summary>
 /// Check if the given item is able to fit in the specified slot on this item storage
 /// (regardless of whether it is occupied)
 /// </summary>
 /// <param name="toCheck"></param>
 /// <param name="inSlot">slot on this item storage that we are seeing if
 /// toCheck fits in</param>
 /// <returns>true iff the item is able to fit</returns>
 public abstract bool CanFit(Pickupable toCheck, SlotIdentifier inSlot);
Example #26
0
 public void RemoveAll(SlotIdentifier slotIdentifier)
 {
 }
Example #27
0
 public void UpdateMinimumFrameTime(SlotIdentifier slotIdentifier, int projectID)
 {
 }
Example #28
0
 public void RemoveAll(SlotIdentifier slotIdentifier, int projectID)
 {
 }
Example #29
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="namedSlot"></param>
 /// <returns>true iff this item storage has the slot with the specified identifier</returns>
 public bool HasSlot(NamedSlot namedSlot)
 {
     return(HasSlot(SlotIdentifier.Named(namedSlot)));
 }
Example #30
0
 public ICollection <ProteinBenchmark> GetBenchmarks(SlotIdentifier slotIdentifier, int projectID)
 {
     return(new List <ProteinBenchmark>());
 }