コード例 #1
0
        public void Start()
        {
            var lampDictionary = CreateFakeLamps();

            var motionEvents  = _scheduler.CreateColdObservable(_motionEvents.ToArray());
            var messageBroker = new FakeMessageBroker(motionEvents, lampDictionary);

            var checkTime    = _periodicCheckTime ?? TimeSpan.FromMilliseconds(1000);
            var timeDuration = _timeDuration ?? 20;

            var mapper = Bootstrap(messageBroker);
            var actor  = mapper.Map <ServiceDTO, LightAutomationServiceProxy>(_serviceConfig);

            _actorContext.Lamps        = lampDictionary;
            _actorContext.Scheduler    = _scheduler;
            _actorContext.MotionEvents = motionEvents;

            StartAndWait(actor);
        }
コード例 #2
0
        Build()
        {
            var hallwayLampToilet     = new FakeMotionLamp(Detectors.hallwayDetectorToilet);
            var hallwayLampLivingRoom = new FakeMotionLamp(Detectors.hallwayDetectorLivingRoom);
            var toiletLamp            = new FakeMotionLamp(Detectors.toiletDetector);
            var livingRoomLamp        = new FakeMotionLamp(Detectors.livingRoomDetector);
            var bathroomLamp          = new FakeMotionLamp(Detectors.bathroomDetector);
            var badroomLamp           = new FakeMotionLamp(Detectors.badroomDetector);
            var kitchenLamp           = new FakeMotionLamp(Detectors.kitchenDetector);
            var balconyLamp           = new FakeMotionLamp(Detectors.balconyDetector);
            var staircaseLamp         = new FakeMotionLamp(Detectors.staircaseDetector);

            var lampDictionary = new Dictionary <string, FakeMotionLamp>
            {
                { Detectors.hallwayDetectorToilet, hallwayLampToilet },
                { Detectors.hallwayDetectorLivingRoom, hallwayLampLivingRoom },
                { Detectors.toiletDetector, toiletLamp },
                { Detectors.livingRoomDetector, livingRoomLamp },
                { Detectors.bathroomDetector, bathroomLamp },
                { Detectors.badroomDetector, badroomLamp },
                { Detectors.kitchenDetector, kitchenLamp },
                { Detectors.balconyDetector, balconyLamp },
                { Detectors.staircaseDetector, staircaseLamp }
            };

            _container = new Container();

            var config = new MapperConfiguration(p =>
            {
                p.CreateMap(typeof(ServiceDTO), typeof(LightAutomationServiceProxy)).ConstructUsingServiceLocator();
                p.CreateMap <AttachedPropertyDTO, AttachedProperty>();

                p.ShouldMapProperty = propInfo => (propInfo.CanWrite && propInfo.GetGetMethod(true).IsPublic) || propInfo.IsDefined(typeof(MapAttribute), false);
                p.ConstructServicesUsing(_container.GetInstance);
            });

            var mapper = config.CreateMapper();

            var scheduler           = new TestScheduler();
            var concurrencyProvider = new TestConcurrencyProvider(scheduler);
            var quartzScheduler     = Mock.Of <IScheduler>();
            var motionEvents        = scheduler.CreateColdObservable <MotionEnvelope>(_motionEvents.ToArray());
            var messageBroker       = new FakeMessageBroker(motionEvents, lampDictionary);

            var checkTime       = _periodicCheckTime ?? TimeSpan.FromMilliseconds(1000);
            var observableTimer = Mock.Of <IObservableTimer>();

            Mock.Get(observableTimer).Setup(x => x.GenerateTime(checkTime)).Returns(scheduler.CreateColdObservable(GenerateTestTime(TimeSpan.FromSeconds(_timeDuration), checkTime)));

            _container.RegisterInstance <IScheduler>(quartzScheduler);
            _container.RegisterInstance <IConcurrencyProvider>(concurrencyProvider);
            _container.RegisterInstance <ILogger <LightAutomationServiceProxy> >(new FakeLogger <LightAutomationServiceProxy>(scheduler));
            _container.RegisterInstance <IMessageBroker>(messageBroker);
            _container.RegisterInstance <IObservableTimer>(observableTimer);

            var areProperties = new Dictionary <string, string>();

            if (!string.IsNullOrWhiteSpace(_workingTime))
            {
                areProperties.Add(MotionProperties.WorkingTime, _workingTime);
            }

            var serviceDto = ConfigureRooms(lampDictionary, areProperties);

            if (_confusionResolutionTime.HasValue)
            {
                serviceDto.Properties.Add(MotionProperties.ConfusionResolutionTime, _confusionResolutionTime.ToString());
            }

            var props = Props.FromProducer(() => mapper.Map <ServiceDTO, LightAutomationServiceProxy>(serviceDto));

            _actorContext.PID = _actorContext.Context.SpawnNamed(props, "motionService");

            _actorContext.IsAlive();

            return
                (
                motionEvents,
                scheduler,
                lampDictionary
                );
        }