Пример #1
0
        private void ReadStateThresholds()
        {
            Assert.IsNotNull(_fingerStateThresholds);
            Assert.IsNotNull(_timeProvider);
            Assert.AreEqual(Constants.NUM_FINGERS, _fingerStateThresholds.Count);

            HandFingerFlags seenFingers = HandFingerFlags.None;

            foreach (FingerStateThresholds fingerStateThresholds in _fingerStateThresholds)
            {
                seenFingers |= HandFingerUtils.ToFlags(fingerStateThresholds.Finger);
                HandFinger finger = fingerStateThresholds.Finger;

                var featureStateProvider = _state.GetStateProvider(finger);
                if (featureStateProvider == null)
                {
                    featureStateProvider =
                        new FeatureStateProvider <FingerFeature, string>(
                            feature => GetFeatureValue(finger, feature),
                            feature => (int)feature,
                            _timeProvider);

                    _state.InitializeFinger(fingerStateThresholds.Finger,
                                            featureStateProvider);
                }

                featureStateProvider.InitializeThresholds(fingerStateThresholds.StateThresholds);
            }
            Assert.AreEqual(seenFingers, HandFingerFlags.All);
        }
Пример #2
0
 public void InitializeFinger(HandFinger finger,
                              FeatureStateProvider <FingerFeature, string> stateProvider)
 {
     _fingerState[(int)finger] = new HandFingerState
     {
         StateProvider = stateProvider
     };
 }
Пример #3
0
        public void AddFeatureServices_AddsFeatureProvider()
        {
            // Arrange
            var services             = new ServiceCollection();
            var featureProvider      = new FeatureProvider(new[] { new TestFeature() });
            var configuration        = new ConfigurationBuilder().Build();
            var featureStateProvider = new FeatureStateProvider(featureProvider, configuration);

            // Act
            ServiceCollectionExtensions.AddFeatureServices(services, featureProvider, featureStateProvider);

            // Assert
            var descriptor = services.FirstOrDefault(sd => sd.ServiceType == typeof(IFeatureProvider));

            Assert.NotNull(descriptor);
            Assert.Equal(ServiceLifetime.Singleton, descriptor.Lifetime);
        }
        public void RegisterConfig(TransformConfig transformConfig, TransformJointData jointData,
                                   Func <float> timeProvider)
        {
            bool containsKeyAlready = _idToTransformStateInfo.ContainsKey(transformConfig.InstanceId);

            Assert.IsFalse(containsKeyAlready,
                           "Trying to register multiple configs with the same id into " +
                           "TransformFeatureStateCollection.");

            var featureStateProvider = new FeatureStateProvider <TransformFeature, string>
                                       // note that jointData and transformConfig are reference types (classes), because they can change
                                       // during run time
                                           ((feature) => TransformFeatureValueProvider.GetValue(feature, jointData, transformConfig),
                                           feature => (int)feature,
                                           timeProvider);
            TransformStateInfo newTransfState = new TransformStateInfo(transformConfig, featureStateProvider);

            featureStateProvider.InitializeThresholds(transformConfig.FeatureThresholds);
            _idToTransformStateInfo.Add(transformConfig.InstanceId, newTransfState);
        }
 public TransformStateInfo(TransformConfig transformConfig,
                           FeatureStateProvider <TransformFeature, string> stateProvider)
 {
     Config        = transformConfig;
     StateProvider = stateProvider;
 }